Skip to content

Instantly share code, notes, and snippets.

@farhaven
Created June 5, 2010 17:55
Show Gist options
  • Save farhaven/426837 to your computer and use it in GitHub Desktop.
Save farhaven/426837 to your computer and use it in GitHub Desktop.
/*
* 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);
}
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment