darcs patch: Add ShowWName a layout modifier to show the workspace...

Hi,
this is a follow up of Don's user survey: David Benbennick suggested
to have the possibility so see the name of the new workspace when you
switch. David Roundy suggested a way to achieve it. And I, with his
help, implemented it.
Still with some problems I seem not to be able to solve. The fist one
is the old thread related problem: since I need to create a window and
destroy it after 1 second (the interval can be configured), I need to
stop the main thread execution for a second. Most of the time xmonad
is blocked in a foreign call (XNextEvent) in the 'forever' loop. This
means I cannot destroy the window in a forked thread (which would be
blocked too): so I have to block the main thread.
But I have to block the main thread in doLayout (actually redoLayout,
since we are talking about a layout modifier), which means we block
*before* returning the windows and rectangles list... which means,
the window with the workspace name is displayed *before* displaying
the workspace itself!
This is the reason why I use xmobar and DynamcLog to know the
workspace I'm in, and this is the reason I did not push this patch.
Perhaps I'm missing something really stupid (David?), but I'm not so
sure...;)
What do you think?
Andrea
Fri Dec 28 19:16:04 CET 2007 Andrea Rossato

On Fri, Dec 28, 2007 at 07:36:06PM +0100, Andrea Rossato wrote:
this is a follow up of Don's user survey: David Benbennick suggested to have the possibility so see the name of the new workspace when you switch. David Roundy suggested a way to achieve it. And I, with his help, implemented it.
Still with some problems I seem not to be able to solve. The fist one is the old thread related problem: since I need to create a window and destroy it after 1 second (the interval can be configured), I need to stop the main thread execution for a second. Most of the time xmonad is blocked in a foreign call (XNextEvent) in the 'forever' loop. This means I cannot destroy the window in a forked thread (which would be blocked too): so I have to block the main thread.
But I have to block the main thread in doLayout (actually redoLayout, since we are talking about a layout modifier), which means we block *before* returning the windows and rectangles list... which means, the window with the workspace name is displayed *before* displaying the workspace itself!
We'd definitely want to figure out a way to get a timer event into xmonad. A stupid way to do this would be by executing spawn "sleep 1 && xmessage -timeout 1 ignorethis" And then looking for this xmessage, removing it from the list to display (since we don't really want it displayed), and also removing the little message that we printed nicely. It's a horrible hack of a way to generate a timer event, but since we only wait for X events and no other, it seems that this is something like the way we need to go (unless there's a nicer way to get X to send us a "timer" event). Another approach, of course, would be to simply call an external program that displays the workspace name and then vanishes. It's a little hokey, but I suspect kdialog could do it pretty nicely. Actually, a simple spawn "kdialog --passivepopup \"" ++ string ++ "\" 1" ought to do the trick. It's less easily configurable (except by kde users), and requires that kdialog be installed, but it's pretty simple. -- David Roundy Department of Physics Oregon State University

On Sat, Dec 29, 2007 at 01:52:48PM -0500, David Roundy wrote:
We'd definitely want to figure out a way to get a timer event into xmonad.
yes, something like this would be great. I don't know is the X server can do that. I need to investigate (but I have the feeling the answer is no).
Another approach, of course, would be to simply call an external program that displays the workspace name and then vanishes. It's a little hokey, but I suspect kdialog could do it pretty nicely.
without installing any 3rd party stuff, I think we could just create some binaries, along with the library created by xmonad-contrib. We could have this very little program to display the workspace name (or any other string), with a timer. Then we could add some other utilities, such as a screen locker, a pointer hider, and so. The stuff I was hacking as xmonad-utils, and that I'm actually using. Or just have this 3 package: xmonad-utils, a small set of x utilities like the one I was talking about. what do you think? Andrea

On Sun, Dec 30, 2007 at 02:29:27PM +0100, Andrea Rossato wrote:
On Sat, Dec 29, 2007 at 01:52:48PM -0500, David Roundy wrote:
We'd definitely want to figure out a way to get a timer event into xmonad.
yes, something like this would be great. I don't know is the X server can do that. I need to investigate (but I have the feeling the answer is no).
I can't help but think that there must be an elegant solution. :(
Another approach, of course, would be to simply call an external program that displays the workspace name and then vanishes. It's a little hokey, but I suspect kdialog could do it pretty nicely.
without installing any 3rd party stuff, I think we could just create some binaries, along with the library created by xmonad-contrib.
I'm not sure which is better. Relying on 3rd party stuff for an optional extension is a pretty nice solution. It's actually quite nice to reuse reuseable components. But you're right that it's definitely less simple for our users...
We could have this very little program to display the workspace name (or any other string), with a timer. Then we could add some other utilities, such as a screen locker, a pointer hider, and so. The stuff I was hacking as xmonad-utils, and that I'm actually using.
Or just have this 3 package: xmonad-utils, a small set of x utilities like the one I was talking about.
what do you think?
Not a bad idea, but I'd really rather not require a whole host of executables. I don't see any fundamental reason why xmonad can't be a single executable... other than perhaps that we've got a bad X11 library that disallows reasonable use. But since dons is now maintaining the X11 package, we could perhaps fix that. Or perhaps there's a non-blocking way to get events? -- David Roundy Department of Physics Oregon State University

On Sun, Dec 30, 2007 at 04:36:49PM -0500, David Roundy wrote:
On Sun, Dec 30, 2007 at 02:29:27PM +0100, Andrea Rossato wrote:
On Sat, Dec 29, 2007 at 01:52:48PM -0500, David Roundy wrote:
We'd definitely want to figure out a way to get a timer event into xmonad.
yes, something like this would be great. I don't know is the X server can do that. I need to investigate (but I have the feeling the answer is no).
I can't help but think that there must be an elegant solution. :(
Here's an idea that's at least self-contained: We could fork a process that waits one second and then uses XSendEvent() to send a message to the other, and then exits. This seems reasonably elegant. It avoids the need for an external binary, it's moderately efficient (probably more so than execing a new binary), and we could even encapsulate it in a simple function. -- David Roundy Department of Physics Oregon State University

On Sun, Dec 30, 2007 at 04:57:47PM -0500, David Roundy wrote:
We could fork a process that waits one second and then uses XSendEvent() to send a message to the other, and then exits. This seems reasonably elegant. It avoids the need for an external binary, it's moderately efficient (probably more so than execing a new binary), and we could even encapsulate it in a simple function.
The problem is that the forked thread will be blocked too as long as the main thread is blocked by XNextEvent. In xmobar Spencer came up with a version of XNextEvent that doesn't block in a foreign call, so that it can be interrupted by an asynchronous exception. This is not going to be feasible in xmonad, unfortunately. Andrea

On Dec 30, 2007 5:28 PM, Andrea Rossato
On Sun, Dec 30, 2007 at 04:57:47PM -0500, David Roundy wrote:
We could fork a process that waits one second and then uses XSendEvent() to send a message to the other, and then exits. This seems reasonably elegant. It avoids the need for an external binary, it's moderately efficient (probably more so than execing a new binary), and we could even encapsulate it in a simple function.
The problem is that the forked thread will be blocked too as long as the main thread is blocked by XNextEvent.
But I didn't suggest to fork a thread, but rather a process. And that's something that ghc's stupidity can't affect. It's somewhat inefficient, but more elegant (and more efficient) than shipping extra binaries. David

On Tue, Jan 01, 2008 at 08:23:42PM -0500, David Roundy wrote:
On Dec 30, 2007 5:28 PM, Andrea Rossato
wrote: On Sun, Dec 30, 2007 at 04:57:47PM -0500, David Roundy wrote:
We could fork a process that waits one second and then uses XSendEvent() to send a message to the other, and then exits. This seems reasonably elegant. It avoids the need for an external binary, it's moderately efficient (probably more so than execing a new binary), and we could even encapsulate it in a simple function.
The problem is that the forked thread will be blocked too as long as the main thread is blocked by XNextEvent.
But I didn't suggest to fork a thread, but rather a process. And that's something that ghc's stupidity can't affect. It's somewhat inefficient, but more elegant (and more efficient) than shipping extra binaries.
sorry David, my fault: I didn't understand at first. This approach seems interesting to me and I'll investigate which Event we could send to have this timer. Thanks, Andrea

On Tue, Jan 01, 2008 at 08:23:42PM -0500, David Roundy wrote:
But I didn't suggest to fork a thread, but rather a process. And that's something that ghc's stupidity can't affect. It's somewhat inefficient, but more elegant (and more efficient) than shipping extra binaries.
I've just pushed XMonad.Util.Timer which exports: startTimer :: Rational -> X TimerId and handleTimer :: TimerId -> Event -> X (Maybe a) -> X (Maybe a) hope this makes sense. I'm using it, now, in XMonad.Layout.ShowWName, which does not require dzen anymore. Thanks for you suggestions. Andrea

On Sat, Dec 29, 2007 at 01:52:48PM -0500, David Roundy wrote:
Another approach, of course, would be to simply call an external program that displays the workspace name and then vanishes. It's a little hokey, but I suspect kdialog could do it pretty nicely. Actually, a simple
spawn "kdialog --passivepopup \"" ++ string ++ "\" 1"
ought to do the trick. It's less easily configurable (except by kde users), and requires that kdialog be installed, but it's pretty simple.
I just pushed a version of ShowWName which uses denz to display to workspace name. dzen is probably the most common application among xmonad users. Hope it can be useful for someone. Andrea

On Dec 31, 2007 8:20 AM, Andrea Rossato
On Sat, Dec 29, 2007 at 01:52:48PM -0500, David Roundy wrote:
Another approach, of course, would be to simply call an external program that displays the workspace name and then vanishes. It's a little hokey, but I suspect kdialog could do it pretty nicely. Actually, a simple
spawn "kdialog --passivepopup \"" ++ string ++ "\" 1"
ought to do the trick. It's less easily configurable (except by kde users), and requires that kdialog be installed, but it's pretty simple.
I just pushed a version of ShowWName which uses denz to display to workspace name.
dzen is probably the most common application among xmonad users.
Hope it can be useful for someone.
Andrea
I just tried this out and it seems to be broken for me. If I add 'showWName' to my layout and restart, it works fine until I close a window: after closing a window, the next workspace switch displays the workspace name just fine, but all subsequent workspace switches just display a little black box, as if the workspace name were empty. If you want I can file a bug report on the google code issue tracker too. -Brent

On Jan 7, 2008 12:28 PM, Brent Yorgey
On Dec 31, 2007 8:20 AM, Andrea Rossato
wrote: Another approach, of course, would be to simply call an external
On Sat, Dec 29, 2007 at 01:52:48PM -0500, David Roundy wrote: program
that displays the workspace name and then vanishes. It's a little hokey, but I suspect kdialog could do it pretty nicely. Actually, a simple
spawn "kdialog --passivepopup \"" ++ string ++ "\" 1"
ought to do the trick. It's less easily configurable (except by kde users), and requires that kdialog be installed, but it's pretty simple.
I just pushed a version of ShowWName which uses denz to display to workspace name.
dzen is probably the most common application among xmonad users.
Hope it can be useful for someone.
Andrea
I just tried this out and it seems to be broken for me. If I add 'showWName' to my layout and restart, it works fine until I close a window: after closing a window, the next workspace switch displays the workspace name just fine, but all subsequent workspace switches just display a little black box, as if the workspace name were empty.
If you want I can file a bug report on the google code issue tracker too.
-Brent
Oh, and just to add, this is not caused by bad interactions with some other layout modifier, as I suspected at first: I tried it with layoutHook = showWName $ Tall 1 (3/100) (1/2) and got the same behavior. -Brent

On Mon, Jan 07, 2008 at 12:29:34PM -0500, Brent Yorgey wrote:
Oh, and just to add, this is not caused by bad interactions with some other layout modifier, as I suspected at first: I tried it with layoutHook = showWName $ Tall 1 (3/100) (1/2) and got the same behavior.
-Brent
Sorry Brent if I didn't come back to you on IRC yesterday... by the way, I'm not able to reproduce your issue, but I've also rewritten the module to use XMonad.Util.Timer and XUtils. can you please give it a try and tell me if the problem persists? Thanks Andrea

On Jan 13, 2008 4:40 AM, Andrea Rossato
On Mon, Jan 07, 2008 at 12:29:34PM -0500, Brent Yorgey wrote:
Oh, and just to add, this is not caused by bad interactions with some other layout modifier, as I suspected at first: I tried it with layoutHook = showWName $ Tall 1 (3/100) (1/2) and got the same behavior.
-Brent
Sorry Brent if I didn't come back to you on IRC yesterday... by the way, I'm not able to reproduce your issue, but I've also rewritten the module to use XMonad.Util.Timer and XUtils.
can you please give it a try and tell me if the problem persists?
Works great! I can't reproduce that problem now. Only thing now is that it seems to ignore the color settings. I get black text on a white background no matter what swn_color and swn_bg_color are set to. (Note that this isn't even the same as the default settings, which are the reverse.) -Brent

On Mon, Jan 14, 2008 at 07:42:33AM -0500, Brent Yorgey wrote:
Works great! I can't reproduce that problem now. Only thing now is that it seems to ignore the color settings. I get black text on a white background no matter what swn_color and swn_bg_color are set to. (Note that this isn't even the same as the default settings, which are the reverse.)
Keep in mind that the configuration is cached, so you need to reset the layoutHook to see the change. If I reset the layout the new configuration takes effect here. Andrea

On Jan 14, 2008 9:24 AM, Andrea Rossato
Works great! I can't reproduce that problem now. Only thing now is
On Mon, Jan 14, 2008 at 07:42:33AM -0500, Brent Yorgey wrote: that it
seems to ignore the color settings. I get black text on a white background no matter what swn_color and swn_bg_color are set to. (Note that this isn't even the same as the default settings, which are the reverse.)
Keep in mind that the configuration is cached, so you need to reset the layoutHook to see the change. If I reset the layout the new configuration takes effect here.
Oh, right, ignore me, I'm a doofus. =) Resetting the layout does the trick. However, it turns out the bgcolor and color were also backwards in the call to paintAndWrite; I've pushed a patch. -Brent

On Mon, Jan 07, 2008 at 12:28:12PM -0500, Brent Yorgey wrote:
I just tried this out and it seems to be broken for me. If I add 'showWName' to my layout and restart, it works fine until I close a window: after closing a window, the next workspace switch displays the workspace name just fine, but all subsequent workspace switches just display a little black box, as if the workspace name were empty.
thanks for the report: I'll look into it (and I'll also try to implement the David's timer idea).
If you want I can file a bug report on the google code issue tracker too.
if you have time, so I can keep a track, great. Thanks, Andrea
participants (4)
-
Andrea Rossato
-
Brent Yorgey
-
David Roundy
-
David Roundy