10

I would like to have a keyboard shortcut to "go to" (focus + raise) window with URGENT flag set which looks like URGENT: it appears on the taskbar (Gnome + Metacity) even if it is on desktop other than current and starts to blink (thanks to @slm for pointing it out).

This window might be on other virtual desktop than current.

In this particular case it is Skype windows which set urgency flag, and so they appear in alt-tab popup (metacity WM) but I can't switch to this window if it is not on current virtual desktop.

I was looking into xdotool and wmctrl command with no luck.

Any ideas or clues?


Update: It appears, that I'm talking about _NET_WM_STATE = _NET_WM_STATE_DEMANDS_ATTENTION ...

pevik
  • 1,397
  • 15
  • 27
roomcays
  • 311
  • 2
  • 8
  • How do you know that the window hsa the URGENT flag? – slm Aug 07 '13 at 15:32
  • Might be helpful: http://it.reddit.com/r/archlinux/comments/tbj6w/setting_wm_urgent_hint/ – slm Aug 07 '13 at 15:36
  • The window manager is really in a better position to do this, why not do this in your window manager? Hmmm, ok, you're using Metacity; if you want fancy stuff, why stick with a minimalistic window manager? – Gilles 'SO- stop being evil' Aug 07 '13 at 23:13
  • @slm: When new message arrives conversation window (which is placed on another desktop) appears on my taskbar with emphasized window name (bold) and blinking. If I click on the taskbar item using MOUSE cursors - WM switches desktop to the one, where conversation window is in, but I can't do it with keystroke, even if this window appears on so called "ALT-TAB" popup. This is probably WM (metacity) issue and is not the case of my question (for now). – roomcays Aug 08 '13 at 11:21
  • UPDATE: OK, it appears, that this behaviour does not mean that URGENCY hint is set on the window. I'll update my question in a moment. – roomcays Aug 08 '13 at 11:32
  • @Gilles I was using `Openbox` untill it started to play ugly things with `PHPStorm` (which I use for work), tried to use `awesome`, but can't live without ALT+TAB, and so the circle closes... – roomcays Aug 08 '13 at 11:44

2 Answers2

4

I think I have found some working solution here.

Bash scripts provided there are what I was looking for and they apparently make use of wmctrl!

For quick access/archiving purposes I copy-n-paste both scripts here:

Jump to the window demanding attention:

#!/bin/bash
activeWinIdLine=`xprop -root | grep _NET_ACTIVE_WINDOW\(WINDOW\) `
activeWinId="${activeWinIdLine:40}"
echo $activeWinId > ~/activeWinId
for id in `wmctrl -l | cut -d " " -f 1`; do
    xprop -id $id | grep "_NET_WM_STATE_DEMANDS_ATTENTION" 2>&1 > /dev/null
    if [ "$?" = "0" ]; then
        wmctrl -i -a $id
        exit 0
    fi
done
exit 1

Jumps back to the window you were busy with:

#!/bin/bash
if [ -f ~/activeWinId ]; then
    origWinId=`cat ~/activeWinId`
    wmctrl -i -a $origWinId
fi

Thanks for discussion, especially @slm for directing me on the right lead.

pevik
  • 1,397
  • 15
  • 27
roomcays
  • 311
  • 2
  • 8
2

There is a small working C project seturgent (thanks hiltjo). Usage:

seturgent <winid> [0|1] # 0: urgent off, 1: urgent on

Copying the source seturgent.c:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

static void die(const char *s) {
    fputs(s, stderr);
    exit(EXIT_FAILURE);
}

static void seturgency(Display *dpy, Window winid, Bool set) {
    XWMHints *hints = XGetWMHints(dpy, winid);
    if(!hints) {
        fputs("seturgent: unable to get window manager hints.\n", stderr);
        return;
    }
    if(set)
        hints->flags |= XUrgencyHint;
    else
        hints->flags &= ~XUrgencyHint;
    if(!XSetWMHints(dpy, winid, hints))
        fputs("seturgent: unable to set urgency hint.\n", stderr);
    XFree(hints);
}

int main(int argc, char **argv) {
    Display *dpy;

    if(argc < 2 || !strcmp(argv[1], "-h")) /* help / usage */
        die("Usage: seturgent <winid> [0|1]\n");
    if(argc == 2 && !strcmp(argv[1], "-v")) /* version */
        die("seturgent-"VERSION" © 2010-2012 seturgent engineer, see " \
            "LICENSE file for details.\n");
    if(!(dpy = XOpenDisplay(NULL)))
        die("seturgent: unable to open display.\n");
    /* set the urgency hint (or not), if not specified its True. */
    seturgency(dpy, (Window)strtol(argv[1], NULL, 0),
               !((argc > 2) && !atol(argv[2])));
    XSync(dpy, False);
    XCloseDisplay(dpy);

    return EXIT_SUCCESS;
}
pevik
  • 1,397
  • 15
  • 27