Suggestion: Edit icewm menu so only one instance of app-select can be launched

Forum Forums antiX-development Development Suggestion: Edit icewm menu so only one instance of app-select can be launched

  • This topic has 6 replies, 3 voices, and was last updated Sep 20-9:28 pm by blur13.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #117116

      During the week-end I took a small deep dive in IceWM documentation.

      One micro-thing that always as bothered me is the fact that in antiX, some apps than can be considered part of the system, like app-select (commonly used as the menu’s app search feature), volumeicon and the “Exit session” window can be launched multiple times. It’s a tiny stupid thing that bothers my sense of how a nice and modern User Interface should work. Since I don’t like to complain about tiny stuff like that, I finally solved it, at least in what regards “app-select”
      That does not make any sense at all and can be partly solved, at least in what concerns app-select in IceWM’s Menu.

      We can just exit app-select’s menu entry (ex: geany ~/.icewm/menu or via Control Centre) and replace it with something like this:

      runonce "Find Apps (and manage their launchers)" /usr/share/icons/papirus-antix/48x48/categories/d-feet.png "app-select.App-select" app-select

      How this works (so you can do the same to other menu entries):
      using “runonce” instead of “prog” allows the program to run just once… but requires a new field, that refers to the classification of the window. That can be (that can be obtained running this command and clicking in the window that we want information about (in this case, app-select)
      xprop | grep WM_CLASS
      command and then clicking the window that we want info about.

      Ex: when we click app-select’s window we get, on the terminal:
      WM_CLASS(STRING) = "app-select", "App-select"

      The new field we have to add to the menu entry is comprised of the results of the command, inside quotes, separated by a dot. (in our case:
      “app-select”, “App-select” turns into “app-select.App-select”

      Note: I edited app-select’s name, as it is shown in the menu to be more descriptive of what the app does. Feel free to use just “App select”, if you wish.

      Save the menu file. Click the app-select menu entry. It’s launched. Click it again, all it does is bring the running app-select window to focus. It only opens a new window if no window is running – that makes sense – it’s almost like the “smart quick launch menu entries” Windows interface has since Windows 7 (that is one of the very few things I like on Windows design) – click a launcher to launch the app or to switch to it (most system related apps only require one window open, not several instances of it).

      Note: to apply the same principle to volumeicon, I’ll try, later, using an alias for it (inspired by the way our startup script launches pipewire related stuff).

      I guess that the “Exit session” window code will have to be edited to allow only one instance of it… but I don’t know python. Any voluntaries to try to achieve this?

      • This topic was modified 7 months ago by PPC.
      • This topic was modified 7 months ago by PPC.

        That’s super cool. I didn’t realize icewm menus had such an option. I love it and I think I’ll be converting a lot of my menu entries to runonce. That’s useful for so many apps and especially settings stuff.

        Making only run once is almost as easy. Just insert two (EDIT:three) lines before the Gtk.main() call, so the last lines of the script should be:

        fullcmd = os.popen("cat /proc/%s/cmdline | xargs -0" % os.getpid()).read()[:-1]
        oldpid = int(os.popen("pgrep -of '%s'" % fullcmd).read())
        if oldpid != os.getpid(): os.kill(oldpid,1)

        EDIT: To deal with the situation I suggested where the script might be launched by something other than “python3” depending on the user’s environment, I added a (somewhat stupid) line to fetch the cmdline of the current instance and use that for the pgrep.

        • This reply was modified 7 months ago by anti-apXos.

          Nice find PPC!

          I wonder if there is something similar to runonce when launching programs using keyboard shortcuts.


            It’s too bad these runonce entries can’t be overridden somehow (like middle-click) to force a new launch if you want it. That would be really nice on the toolbar.

            I wonder if there is something similar to runonce when launching programs using keyboard shortcuts.

            I recently dealt with the fact that iceWM key shortcuts can’t take multiple commands (including && or ||) and a solution is to use sh -c “$CMD”, so I was going to suggest key "Super+F1" sh -c "pidof app-select || app-select"
            but that doesn’t also raise the previous window, which is no good.

            Naturally, StackExchange suggests that Linux has a few tricks up her sleeve, so how about key "Super+F1" sh -c "wmctrl -a ' App Select' || app-select"

            If the window title needed by wmctrl is not obvious, you can use wmctrl -l to see a list of currently open windows. Of course, some programs change their window titles depending on context, but for many cases this should work.

            • This reply was modified 7 months ago by anti-apXos.


              This is great! Thank you! Before I learned about bash -c or sh -c I just wrote shell scripts to deal with the limitations of the icewm keys file.


                I was looking at icesh, and I see that it also offers this runonce option, so I figured I’d share it here for documentation’s sake.

                icesh -class "lxtask.Lxtask" runonce lxtask
                does not focus the previous instance, the way the runonce menu item does, but icesh is pretty damned cool and accepts if…else… options via a command line. So we can do
                icesh if -class "lxtask.Lxtask' then activate else runonce lxtask

                I don’t know if that’s any better than the method using wmctrl. Less general, but maybe more consistent.

                Potentially a lot more could be done with icesh, especially using if…else… options, so if you’re into keyboard shortcuts (and I am), this is real cool. IceWM continues to impress.


                  I agree! I got this one in my keys file:

                  # Toggle Window decorations On/Off
                  key "Super+w" /bin/bash -c "icesh -f if -P _NET_FRAME_EXTENTS=0 then bordered else borderless"

                  Thats straight from the manpage for icesh but I found it really useful.

                Viewing 7 posts - 1 through 7 (of 7 total)
                • You must be logged in to reply to this topic.