Page 1 of 6 123 ... LastLast
Results 1 to 10 of 52

Thread: HOWTO: Make a launcher restore an open window (dock-like)

  1. #1
    Join Date
    Dec 2006
    Beans
    678

    HOWTO: Make a launcher restore an open window (dock-like)

    This outlines an easy method to modify the behavior of select launchers so that when clicked, they open the program if no instance of the program is already running, but restore focus to the program if an instance is already running. It also allows for the ability to hide the window from the taskbar, so that some launchers become their own icons. In other words, you can create a custom "icon box" for some programs (which double as launchers), while other programs use the task list.

    Current version: 0.52

    UPDATE (25 Dec 2007): Posted version 0.52, which should resolve problems with certain programs not responding correctly to arguments.

    The current version, allows for minimizing windows, multiple windows, and a few other goodies. This is still somewhat beta, but should be stable. Moreover, I hope to much more tightly integrate this into the gnome interface at some point, which would make it much easier to use.
    Limitations compared to full-blown dock programs:
    1) You must manually apply to all launchers.
    2) It does not trap instances launched via some other means (e.g., unmodified launcher, browser link in another program, etc.); however, you can still trigger them to hide by clicking on the launcher if it has the -h option (it will now hide all matching windows, not just those launched from the panel initially).
    3) Minimization is dependent on a keyboard shortcut (due to a wmctrl bug), so must be set using the -k option if it is not Alt+F9 (the default for Metacity).

    On the other hand, launch-restore integrates into your existing panel (of any type), so does not require a commitment to a full-blown dock.

    Installation is simple: just install the attached .deb file, which just installs launch-restore into /usr/local/bin, and downloads wmctrl & xautomation if they are not on your system (needed for window handling). If you later want to remove the script, just use synpatic or apt-get to remove "launch-restore" and it will undo everything.

    In the simplest case, all you need to do is modify the launcher (I only do this to the icons I put on my panel, but you could also modify the menu entries) by inserting
    Code:
    launch-restore MATCH
    in front of the program name (and any parameters) already in the launcher. MATCH is a string specific to each program that wmctrl will use to determine if the program is already running. MATCH is tested against either the "name" of a window (i.e., the title you see in the title bar) or the "class" (usually something related to the name of the actual executable). By default, "class" is used, as that is more reliable, but for some programs that won't work. Note that all matching is case-sensitive.

    If you wish to just match against the name, you use the "-n" option. For example, to match Firefox, your launcher should look like:
    Code:
    7.04 and earlier: launch-restore -n Firefox firefox %u
    7.10: launch-restore -n Firefox-bin firefox %u
    (The %u is there so you can drag & drop a file onto the Firefox icon and have it open in Firefox.)

    To determine the class of a program, run this in a terminal with the application(s) running:
    Code:
    wmctrl -lx
    Which will produce an output something like this (from my system at the moment, running 7.04):
    Code:
    0x01800003 -1 panel.fbpanel         desktop panel
    0x00c00003 -1 gnome-panel.Gnome-panel  desktop Left Expanded Edge Panel
    0x00c00031 -1 gnome-panel.Gnome-panel  desktop Bottom Expanded Edge Panel
    0x01000021 -1 desktop_window.Nautilus  desktop Desktop
    0x0260007c  0 Gecko.Firefox-bin     desktop Ubuntu Forums - Post New Thread - Firefox
    0x02800003  0 mousepad.Mousepad     desktop launch-restore
    0x02a00003  1 mousepad.Mousepad     desktop to do.txt
    0x03000073  1 Gecko.Mozilla-thunderbird-bin  desktop Inbox for user@domain.com - Thunderbird
    0x03400062  0 VCLSalFrame.DocumentWindow.OpenOffice.org 2.0  desktop file.ods - OpenOffice.org Calc
    0x02c0001f  0 gnome-terminal.Gnome-terminal  desktop user@desktop: ~
    user@desktop:~$
    The first 2 columns are the window ID and desktop, and can be ignored. The 3rd column is the "class" - you can choose any fragment of it to match against (e.g., "Firefox" for firefox, "thunderbird" for Thunderbird, "OpenOffice" for OpenOffice). 4th column is computer, and can be ignored. Final column is the "name" (i.e., the title on the titlebar) for each window. The "class" will be constant for every instance of a particular program, while the "name" frequently changes for most programs, and so "class" is the easier target. Also, if you happen to be browsing a website with "Thunderbird" in the title, you may end up restoring focus to Firefox instead of Thunderbird if you match on Thunderbird by name instead of class (and for many other cases).

    You can pass additional parameters to launch-restore, here are the most interesting (run it in a terminal to see all parameters):
    -x : prevents passing of program arguments to program if an instance of program is already running (I use this for shortcuts to files on my panel, as otherwise the running version receive focus, but then a second copy starts anyway).
    -h : hides the program from the taskbar (and alt+tab switching - at least in Gnome). Note that it may very briefly appear before vanishing.
    -m: prevents minimization by clicking on the launcher again.
    -a & -d: affects how the program deals with multiple windows.
    -k to change the minimize key shortcut.
    -f to restore focus even when passing arguments (e.g., when dropping a link onto the Firefox launcher).
    Use "launch-restore --help" in a terminal for full details of all options.

    Examples:
    Code:
    launch-restore -h thunderbird-bin mozilla-thunderbird [in 7.04 and ealier]
    launch-restore -h Thunderbird-bin thunderbird [in 7.10]
    launch-restore Firefox firefox %u [in 7.04 and earlier]
    launch-restore Firefox-bin firefox %u [in 7.10]
    launch-restore Toplevel /usr/bin/idle
    launch-restore -n -k R_Alt,F5 Audacious audacious
    launch-restore --a -m -x nautilus.Nautilus /home/user/
    1 & 2) launches Thunderbird and hides it from the taskbar.
    3 & 4) launches Firefox, matching on class (although using "-n" and matching on name would also work with no further changes).
    5) launches the python IDLE IDE, and is an example of a program that is difficult to match (the title contains no fixed information at all, and the class is bizarre, but at least "Toplevel" appears to be unqiue on my system).
    6) launches audacious, and like Firefox works exactly the same with or without "-n". The -k option resets the "minimize" keyboard shortcut to the Right Alt + F5; this is just an example, it should match the shortcut for your window manager (Metacity's default shortcut is automatic).
    7) launches/restores a Nautilus window to your home folder (only starting 1 instance), prevents it from being minimized when the launcher is clicked again, and will match all windows on the current desktop if multiple windows exist.

    Additionally, you could combine this with the "easy" gnome dock approach to enhance the dock behavior for some launchers: http://www.ubuntuforums.org/showthread.php?t=333322.

    Note that if used with firefox when a window list is still on your panel, you will get a "starting firefox" message in your panel each time you click the launcher; this is due to a bug ("feature") in Gnome, and I cannot make it go away. In 7.10, this bug also affects Thunderbird.

    I'd hoped to integrate this into X better, including replacing the need for wmctrl and xautomation (to execute the keyboard shortcut to minimize windows), and creating a background daemon that would simplify application. However, upon examining the available tools to do this tasks, I've concluded that it would be a tremendous amount of effort (weeks of full-time effort) for very little gain, as X simply does not allow for some of what I'd like to accomplish, and I'd spend most of my effort on very low-level code to ensure things don't get too slow. While I may revisit this program over time, and will still make an effort to fix bugs that anyone finds in the current version, I don't anticipate any major updates, as I simply do not have the time required. The script is released under the GPL, so anyone who wants to spend the time is free to do so.

    Please post if you encounter any problems and I will modify the script accordingly.
    Attached Files Attached Files
    Last edited by tweedledee; December 26th, 2007 at 09:31 PM. Reason: Update to version 0.52, update for Gutsy

  2. #2
    Join Date
    Feb 2007
    Beans
    191

    Re: HOWTO: Make a launcher restore an open window (dock-like)

    I've recently been configuring my machine more and more OSX-like (after realizing that the dock was such a genius way to streamline the desktop) and was having a bit of a hassle because I still needed a taskbar SOMEWHERE, but now I can keep the darned thing hidden most of the time thanks to this.

    One thing I did notice though is that when you click to restore firefox it seems another window which says "starting firefox" ticks away for a couple seconds (and the "working" mouse icon appears). It disappears, and firefox does focus immediately, but it seems like there should be some way around that. This seems like a good and cheap step to take to make the desktop neater without adding a ton of bells and whistles.

  3. #3
    Join Date
    Dec 2006
    Beans
    678

    Re: HOWTO: Make a launcher restore an open window (dock-like)

    Quote Originally Posted by Mblackwell View Post
    One thing I did notice though is that when you click to restore firefox it seems another window which says "starting firefox" ticks away for a couple seconds (and the "working" mouse icon appears). It disappears, and firefox does focus immediately, but it seems like there should be some way around that. This seems like a good and cheap step to take to make the desktop neater without adding a ton of bells and whistles.
    I believe this is related to a bug in the current (Edgy) version of Gnome that has trouble determining when certain programs start (e.g., many "administrative programs" leave that message open long after the window opens). Of the programs I set up this way, Firefox is the only one that does this, and not always (e.g., clicking on a link in Thunderbird or running "firefox" in a terminal when Firefox is open doesn't trigger that behavior). I'm hoping it is resolved in Fiesty. The other problem I have with Firefox is that if you initially open it another way (e.g., via a link in Thunderbird), it doesn't hide properly. I intend to address that problem when I have some time to sort it out.

  4. #4
    Join Date
    Feb 2007
    Beans
    191

    Re: HOWTO: Make a launcher restore an open window (dock-like)

    It would be great if there was some way to "open all" (show all windows from an app), and also a minimize. I still need the taskbar from time to time, or ALT+TAB. It would be great to get rid of the need entirely. Those two things would pretty much do it I think.

    Also I noticed the script has a hard time with file browser things. I tried setting it up so I could open my home folder and it didn't always work (wouldn't always open a new one), and if there was some way to do that and then also view all Nautilus windows (like above) again it would alleviate some trouble.

    Maybe there needs to be some extra integration with an applet like "Alltray" ? Then you could even allow new programs to appear on the bar (via the tray).

  5. #5
    Join Date
    Dec 2006
    Beans
    678

    Re: HOWTO: Make a launcher restore an open window (dock-like)

    Quote Originally Posted by Mblackwell View Post
    It would be great if there was some way to "open all" (show all windows from an app), and also a minimize. I still need the taskbar from time to time, or ALT+TAB. It would be great to get rid of the need entirely. Those two things would pretty much do it I think.
    Not sure I understand. For the open all, do you mean something like the Mac's Expose feature? Or just a way to tell a launcher to instead of showing the first window that matches, show all of them (al the time)? The first choice is impossible for this level of application; the second might be workable, but gets a little complicated if the windows from the app are on different desktops. Also, it could cause unpredictable behavior with the focus, as sometimes dialog boxes restrict focus to the rest of the program, but may end up hidden behind the main program window (e.g., the "Save/Open" dialogs). Some programs would work better than others.

    For the minimize, do you basically mean something like Alltray's ability to minimze an app to the system tray? If so, you'd just need to modify the invocation in the launcher to trigger the Alltray aspect as well (it's been a while since I played with that, I don't remember exactly how it works).

    Also I noticed the script has a hard time with file browser things. I tried setting it up so I could open my home folder and it didn't always work (wouldn't always open a new one), and if there was some way to do that and then also view all Nautilus windows (like above) again it would alleviate some trouble.
    Could you post the command you are using, and describe any patterns you've noticed for when it does and doesn't work?

    Maybe there needs to be some extra integration with an applet like "Alltray" ? Then you could even allow new programs to appear on the bar (via the tray).
    I see your point, but personally dislike that solution. I tend to agree with the Gnome developers that the system tray should be reserved for "notification" things, and applications should not hang out there; it really irritates me when programs put themselves there (one of the major reasons I stopped using Opera and dislike KDE). Of course, I also keep the taskbar because for some programs I find the descriptions to be useful; the others I just hide with the launcher.

  6. #6
    Join Date
    Feb 2007
    Beans
    191

    Re: HOWTO: Make a launcher restore an open window (dock-like)

    I meant just expose all application windows of a specific program.

    I tried different things, I tried launchingby checking "File Browser" as a name, and /home/ as the command, also I tried invoking Nautilus and looking for the nautilus.Nautilus class (as well as File Browser).

    It seems to be okay if a window already exists, it will restore it. But it doesn't seem to be able to create one as long as "launch-restore" is there.

    And no, for minimize I just meant simply that if I click the Firefox button and a Firefox window (or windows) is already open it will minimize it.

  7. #7
    Join Date
    Dec 2006
    Beans
    678

    Re: HOWTO: Make a launcher restore an open window (dock-like)

    Quote Originally Posted by Mblackwell View Post
    I meant just expose all application windows of a specific program.
    I think I can implement that - give me a few days.

    I tried different things, I tried launchingby checking "File Browser" as a name, and /home/ as the command, also I tried invoking Nautilus and looking for the nautilus.Nautilus class (as well as File Browser).

    It seems to be okay if a window already exists, it will restore it. But it doesn't seem to be able to create one as long as "launch-restore" is there.
    Code:
    launch-restore nautilus.Nautilus nautilus
    works for me. Just matching "Nautilus" focused the desktop instead (which makes sense, if perhaps being unexpected).

    And no, for minimize I just meant simply that if I click the Firefox button and a Firefox window (or windows) is already open it will minimize it.
    Ah. That is also possible. I will implement that at the same time as the "all windows."

    I see three issues with implementing those features usefully - let me know what you might prefer.

    First, should the launcher minimize or restore a window if you are currently focused on another application and click the launcher for the unfocused window (assuming it is not minimized)?

    Second, in the event you are using multiple desktops and have windows from the same program spread out (e.g., Firefox), should the launcher only show all of them on the current desktop, or move them all to the current desktop and show them?

    Third, when showing all, what visual appearance might work best? E.g., I could set it to simply bring all the firefox windows to the top of the window stack, giving focus to one, but in the event one or more windows are maximized only a single window will still be visible. I could make an attempt to tile or otherwise arrange the windows, but that might lead to unpredictable effects, and might get annoying if you have to constantly rearrange windows after showing them.

  8. #8
    Join Date
    Feb 2007
    Beans
    191

    Re: HOWTO: Make a launcher restore an open window (dock-like)

    First off thanks, that piece of code works just dandy.

    As far as the issues go:

    1) It should probably "restore" the window, since for instance if you have a window (or windows) unfocused but not minimized but buried behind other application windows this would bring the desired application to the front.

    2) This is an interesting question. I guess it would depend. If you have an application spread across multiple desktops it should only show the windows on the current desktop, otherwise I would say it if there was a way to switch desktops and restore the application (if it only exists on a single desktop) that would be impressive. Really you should do what's easiest though.

    3) I wonder if there's a way to have the "most recent" window brought to the top (or some way of maintaining what the window stack order was). You could also perhaps handle it by saying that if you have minimized windows in an application and click the button those will be "restored"...

    Which brings me to an issue you didn't mention, that being that if you click the application button it should check if there's any minimized windows, and restore those.

    So I guess it would go something like:

    Unfocused Application: Restore All
    Focused Application with some minimized windows: Restore All Minimized
    Focused Application with nothing minimized: Minimize All

    Just by doing that you create an easy workflow because say a window pops open in Firefox but you don't want to use it just then you can minimize it, and when you click the Firefox button it will be brought back to the top.

  9. #9
    Join Date
    Dec 2006
    Beans
    678

    Re: HOWTO: Make a launcher restore an open window (dock-like)

    Hm. I almost have it working, but have run into two snags. First, it turns out that wmctrl is broken with respect to minimizing windows, and as it hasn't been updated in two years, I'm not optmistic for a fix. I have a workaround, but it's awkward and needs some tweaking to work exactly right (it currently tends to minimize multiple windows unexpectedly). As for multiple windows, I've determined it is possible, but awkward and slow with the implementation I have right now.

    In short, getting these working is going to take longer than I thought, which means I probably won't finish it for a few weeks due to other pressing matters. With luck, I should have something working around the end of April.

  10. #10
    Join Date
    Feb 2007
    Beans
    191

    Re: HOWTO: Make a launcher restore an open window (dock-like)

    No hurries. I'd rather have it working correctly than being frustrating .

Page 1 of 6 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •