At Mon, 9 Feb 2009 21:05:43 +0100
Zsolt Udvari wrote:

> Hi all!
> 
> Is there any solution to set client's urgent flag manually? I want try
> set c.urgent but it didn't work.
> What I want: I'm using dvtm and it can't "compile" beep to urgent
> (like urxvt), so I want create a small script or anything else to
> irssi.
> Anyone has a usable idea?
> 
> Zsolt
> 

Try the attached code. If executed inside a terminal, it sets the terms urgency
hint, waits for a keypress and unsets the hint. It works fine with URxvt, but
YMMV.
-- 
    Gregor Best
/* 
 * A simple example of setting the XUrgencyHint on an xterm from a program
 * running in it. Compile with:
 * 
 *     gcc -L/usr/X11R6/lib -lX11 urgent.c -o urgent
 * 
 */

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

static int set_urgency(Display *dpy, Window id, int set)
{   XWMHints *hints=XGetWMHints(dpy, id);

    if(hints==NULL)
        return 0;

    if(set)
        hints->flags|=XUrgencyHint;
    else
        hints->flags&=~XUrgencyHint;

    return (XSetWMHints(dpy, id, hints)!=0);
}

int main(void)
{   Display *dpy;
    const char *ids;
    Window id;

    ids=getenv("WINDOWID");

    if(ids==NULL)
    {  fprintf(stderr, "WINDOWID not set.");
       return EXIT_FAILURE;
    }

    id=atoi(ids);

    dpy=XOpenDisplay(NULL);

    if(dpy==NULL)
    {   fprintf(stderr, "Unable to open display.");
        return EXIT_FAILURE;
    }

    /* Set the flag */
    if(!set_urgency(dpy, id, 1))
    {   XCloseDisplay(dpy);
        fprintf(stderr, "Unable to set urgency.");
        return EXIT_FAILURE;
    }
    XFlush(dpy);

    getchar();
    
    /* Unset the flag */
    if(!set_urgency(dpy, id, 0))
    {   XCloseDisplay(dpy);
        fprintf(stderr, "Unable to unset urgency.");
        return EXIT_FAILURE;
    }
    XFlush(dpy);

    XCloseDisplay(dpy);

    return EXIT_SUCCESS;
}

Attachment: signature.asc
Description: PGP signature

Reply via email to