cat /dev/maxilys

A glance in the mind of a KDE/Linux developer to see how ideas turn into code.

2007-02-24

KDE: Late midday news

The Kate Session Applet is on its way toward completion. I added the auto-close feature and enabled the use of the keyboard modifiers during drop to launch a new instance of Kate.

The auto-close feature was really fun to implement. I knew I had to set a flag to signal a menu opening and then... what? I didn't investigate how Qt does to close a menu but there are --at least-- no public method. So, what I did is set a flag when Qt sends the signal aboutToShow() and unset it when I receive aboutToHide(). And finally, in my slot that is called after a click, I just refused to open the menu when the flag is set and unset it for the next time.

It didn't work. Period. When the second click occurs, Qt closes the menu before (re-)opening it. It's stupid but logic.

So I did something also stupid. I didn't unset the flag in the slot connected to the signal aboutToHide(). I thought that this way the menu would open only once and all I'll have to do would be to find another place to unset the flag.

It worked... sort of. The menu opened only every two clicks. It's stupid but logic too. :-)

The solution came from one of these mysterious background process that I initiated in my mind while I was typing this blog... and realizing that what I was typing meant that the menu would open only every two clicks. (I really have a twisted mind...)

To open the menu I do:
x = theMenu->exec( theButton->mapToGlobal(QPoint(x, y)) );

So...
if ((x == -1) && (theButton->hasMouse()))
{
// It was a click on "my" button that closed the menu.
// I will just refuse the next opening.
// Since Qt already closed the menu, it will look like
// that it was the click that did it... and it did!
menuIsOpened = true;
}
else
{
// The click occured on an entry of the menu
// or elsewhere that lead to the closure.
// I'm free to open on next click.
menuIsOpened = false;
}

(And no, I'm not that verbose in my comments.)
$ make
(blah blah blah...)
$ su
# password:
# make install ; exit
(blah blah blah...)
$ dcop kicker kicker restart

And it just works... Right now while I'm typing.

As for the keyboard modifiers, I decided to use them when I realized that dropping files on Kate's icon in the panel used to launch a new instance and that I implemented just the opposite: Drops re-use the first instance of Kate that KDE will find. (Again this problem of the virtual desktops and the invisible openings...) Any way, I allowed you to hold whatever keyboard modifier you want (Shift, Control, Alt, Meta) when you drop files and in that case a new instance will be launched.

This behavior is even better than before because you need to use a keyboard modifier only once. If you have some after-thoughts, you just have to drop the new files directly on Kate.

I just got an idea. What if you could choose on which Kate you want to drop your files when several instances are opened? I mean, instead of letting KDE decide for you. That's easy through DCOP and Kate is nice enough to let us know what session she uses, how many files it contains. And there's probably more. I barely scratched the surface while I was looking if it was possible to have the title of the windows. It isn't but the name of the sessions will do the trick. I will investigate further. If it's not too much for a poor little applet...

Maybe.

Labels: , ,

2 Comments:

At 24 February, 2007 21:53, Blogger Tomasu said...

You made me think of something, I'm not sure if this is what you already explained or not, but its a good idea:

If you hover over the kate session menu icon/applet/thing for a few seconds instead of immediately dropping, you open a little extender window (no window title or anything) which shows the current open kate sessions with info, and lets you drop on those.

ps, I love the kate session menu :) I have entirely too many items in mine though (45 :o).

 
At 25 February, 2007 00:45, Blogger Maxilys said...

That's very close from what I had in mind and I love your idea about how to propose where to drop --minus the delay that isn't necessary.

Great spirits always meet. ;-)

 

Post a Comment

<< Home