Subscribe to Grim's Projects        RSS Feed

Linux Launcher/Root Menu in Java

Icon Leave Comment
The compulsory screenshot:
Attached Image
That's what my current Linux setup looks like. It's an Arch Linux running DWM as the window manager. I switched from JWM to SithWM and finally settled at DWM.

Why DWM? Lightweight, so uses very few resources. It's floating mode is tantamount to JWM/SithWM. Workspace switching is much faster (may not even be workspaces from what I've read). Very easily customizable/navigable with the keyboard. However, these reasons are supplementary to the most important reason which is that it properly focuses Java applications. Window managers on Linux seem to have a hard time giving a Java application the focus. What I mean is let's say I use a tabulator key binding to switch to the Java window, typically what will happen, regardless of whether the window manager uses sloppy/click focus, is that you need to click some component within the Java application itself or double-click the window area to sort of "activate" the inner focus. It's odd, DWM on the other hand, when I bring up the Java application (by whichever means DWM provides) the Java application, and its components, behave as expected.

Gripes about DWM? No function to move/resize without repainting the window, a no solid drag (as in SithWM), which greatly speeds up these operations (particularly with Swing heavy Java). This can be patched though, I just haven't looked into it. Keyboard control is lacking in terms of move/resize operations, it necessitates a mouse (this can be patched, but again, haven't looked into it). Thusly, these gripes can be remedied. The one that can't be so readily remedied is the lack of a launcher/root menu/start menu/whatever other name it goes by these days. I basically wanted something simple, but the ones that tend to have the simple menus (openbox, jwm, sithwm, fluxbox, etc.) also include the window manager. It seems like you just can't win sometimes. DWM does have a launcher if you also install dmenu. However, dmenu is a lookup launcher, which means you have to recall to some degree what the applications are called and such.

I know this may seem trivial, but my memory is pretty poor. I'd rather have the OS recall what the programs are, then have to do so myself, particularly if they involve setting certain parameters/flags each time I execute a binary (for instance, xterm).

I looked around, but most of the solutions I found were heavyweight, and primarily geared towards Ubuntu users. If anyone can provide substance regarding some alternatives, I'm all ears.

In the interim though, I basically started coding my own, which I called Big Menu. That's what you see in the screenshot. It's a simplistic design that boils down to a JFrame with a JMenuBar that makes use of the Runtime.getRuntime().exec() method to launch Linux binaries. Not the most complex or fancy piece of software, but it does what I want.

Currently, everything is hard-coded, which is silly (though faster in terms of performance). I plan to enhance it through a configurable XML file which will allow you to manipulate the overall structure of Big Menu, that way there's no need to keep editing/recompiling when I want to make a change to it. It works as expected and solves my problem.

There are some things it is lacking in. Since the window is inherently created floating (DWM does this because it respects the size hints, if any, of a window), it is always on top of other windows. Of course, this can be solved by switching everything to floating mode, but that's less than elegant, I prefer to send Big Menu to another workspace to keep it out of the way. It would be nice to be able to hide/unhide it through the use of a Listener of some sort (or possibly a keybinding), but I'm unsure as to whether or not I could do that purely in Java (without some sort of JNI).

Because it's an application window it appears in the status bar at the top and only on one workspace (can be sent to all workspaces via DWM functions), whereas something like wbar does not appear in the status bar and instantiates on all workspaces automatically. The behavior of wbar is ideally what I want to emulate.

There's also a "glitch" that I can't seem to figure out or work around. When I launch an application, there is obviously a delay between the click on Big Menu and the actual displaying of said application. If in the interim of click/display I happen to click on Big Menu again, and the newly loaded application appears during that time, everything seems to freeze. By everything, I mean everything except the mouse pointer. The status bar also display the title of the application, as opposed to showing "Big Menu". So it would appear the application has the focus. None of the DWM keybindings work either, I can't switch workspaces or windows. Just plain odd. If anyone knows how to make a JFrame give up the focus programatically, I'd appreciate the hint.

0 Comments On This Entry