xwindow.h File Reference

#include <X11/Xlib.h>
Include dependency graph for xwindow.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

G_BEGIN_DECLS void window_set_services (void)
Window get_application_window (const char *app_name)
void window_activate (Window win)
Window get_active_window (void)
char * get_application_of_window (Window win)
gint window_get_idle_time (void)
void print_window_list ()

Function Documentation

Window get_active_window ( void   ) 
char* get_application_of_window ( Window  win  ) 

Definition at line 218 of file xwindow.c.

References g_display, and LOGPRINTF.

00219 {
00220     gchar *app_name = NULL;
00221     XClassHint hint;
00222     
00223     LOGPRINTF("entry: %d", (int) wnd);
00224 
00225     if (XGetClassHint(g_display, wnd, &hint))
00226     {
00227         LOGPRINTF("Window %s, %s", hint.res_name, hint.res_class);
00228         app_name = g_strdup(hint.res_name);
00229         if (hint.res_name) XFree(hint.res_name);
00230         if (hint.res_class) XFree(hint.res_class);
00231         return app_name;
00232     }
00233     
00234     return NULL;
00235 }

Window get_application_window ( const char *  app_name  ) 

Definition at line 101 of file xwindow.c.

References atom_client_list, data, g_display, LOGPRINTF, and WARNPRINTF.

Referenced by on_check_child_window(), and process_activate().

00102 {
00103     LOGPRINTF("entry: %s", app_name);
00104     
00105     Atom type;
00106     int format;
00107     unsigned char *data = NULL;
00108     unsigned long n_items, bytes_after;
00109     int result;
00110     int i;
00111 
00112     g_return_val_if_fail(app_name != NULL, 0);
00113     
00114     // get list of available windows
00115     //
00116     result = XGetWindowProperty(g_display, RootWindow(g_display, DefaultScreen(g_display)), 
00117                                 atom_client_list,
00118                                 0, 10000L,
00119                                 False, XA_WINDOW,
00120                                 &type, &format, &n_items,
00121                                 &bytes_after, (unsigned char **)&data);
00122 
00123     if (result != Success || data == NULL || n_items == 0)
00124     {
00125         if (data) XFree(data);
00126         WARNPRINTF("failed to get client list, %d (items=%ld)", result, n_items);
00127         return None;
00128     }
00129 
00130     // check backwards as new application is likely last in line
00131     for (i = n_items-1; i >= 0; i--)
00132     {
00133         XClassHint hint;
00134         Window wnd = ((Window*)data)[i];
00135         
00136         // get name of application of the window
00137         //
00138         if (XGetClassHint(g_display, wnd, &hint))
00139         {
00140             LOGPRINTF("Window [%d] %d, %s", i, (guint) wnd, hint.res_name);
00141             
00142             if (strcmp(hint.res_name, app_name) == 0)
00143             {
00144                 // found our application
00145                 if (data) XFree(data);
00146                 return wnd;
00147             }
00148         }
00149     }
00150     
00151     if (data) XFree(data);
00152     return None;
00153 }

Here is the caller graph for this function:

void print_window_list (  ) 

Definition at line 261 of file xwindow.c.

References atom_client_list, data, g_display, and WARNPRINTF.

Referenced by testing_list_tasks().

00262 {
00263     Atom type;
00264     int format;
00265     unsigned char *data = NULL;
00266     unsigned long n_items, bytes_after;
00267     int result;
00268 
00269     // get list of available windows
00270     //
00271     result = XGetWindowProperty(g_display, RootWindow(g_display, DefaultScreen(g_display)), 
00272                                 atom_client_list,
00273                                 0, 10000L,
00274                                 False, XA_WINDOW,
00275                                 &type, &format, &n_items,
00276                                 &bytes_after, (unsigned char **)&data);
00277 
00278     if (result != Success || data == NULL || n_items == 0)
00279     {
00280         if (data) XFree(data);
00281         WARNPRINTF("failed to get client list, %d (items=%ld)", result, n_items);
00282         return;
00283     }
00284 
00285     printf("%s() WINDOWS (%lu)\n", __func__, n_items);
00286     
00287     unsigned int i;
00288     for (i = 0; i < n_items; i++)
00289     {
00290         XClassHint hint;
00291         Window wnd = ((Window*)data)[i];
00292         
00293         // get name of application of the window
00294         //
00295         if (XGetClassHint(g_display, wnd, &hint))
00296         {
00297             printf("  Window [%d] %d, %s\n", i, (guint) wnd, hint.res_name);
00298         }
00299     }
00300     if (data) XFree(data);
00301 }

Here is the caller graph for this function:

void window_activate ( Window  win  ) 

Definition at line 186 of file xwindow.c.

References atom_active_window, atom_wm_user_time, g_display, and LOGPRINTF.

Referenced by child_activate(), on_window_open_callback(), and process_activate().

00187 {
00188     LOGPRINTF("entry");
00189 
00190     guint32 timestamp = gtk_get_current_event_time();
00191 
00192     // update user time for window
00193     XChangeProperty(g_display, win, atom_wm_user_time, XA_CARDINAL, 32, PropModeReplace, (guchar *) &timestamp, 1);
00194     
00195     XEvent ev;
00196     memset(&ev, 0, sizeof ev);
00197     ev.xclient.type = ClientMessage;
00198     ev.xclient.window = win;
00199     ev.xclient.message_type = atom_active_window;
00200     ev.xclient.format = 32;
00201     ev.xclient.data.l[0] = 1;
00202     ev.xclient.data.l[1] = 0;
00203     ev.xclient.data.l[2] = 0;
00204     ev.xclient.data.l[3] = 0;
00205     ev.xclient.data.l[4] = 0;
00206     
00207     // activate/raise window
00208     //
00209     XSendEvent(g_display,
00210                RootWindow(g_display, DefaultScreen(g_display)), 
00211                False,
00212                SubstructureRedirectMask, 
00213                &ev);
00214 }

Here is the caller graph for this function:

gint window_get_idle_time ( void   ) 

Definition at line 238 of file xwindow.c.

References g_display, and LOGPRINTF.

Referenced by on_idle_timeout().

00239 {
00240     gint idle_time = -1;
00241     static XScreenSaverInfo *info;
00242 
00243     LOGPRINTF("entry");
00244     
00245     info = XScreenSaverAllocInfo();
00246     if (info != NULL)
00247     {
00248         XScreenSaverQueryInfo(g_display, RootWindow(g_display, DefaultScreen(g_display)), info);
00249         idle_time = (info->idle) / 1000;
00250         XFree(info);
00251     }
00252     return idle_time;
00253 }

Here is the caller graph for this function:

G_BEGIN_DECLS void window_set_services ( void   ) 

File Name : xwindow.h

Description: X11 Window System functions Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Definition at line 81 of file xwindow.c.

References atom_active_window, atom_client_list, atom_wm_user_time, g_display, LOGPRINTF, and on_x_error().

Referenced by main().

00082 {
00083     // make Xlib thread safe
00084     XInitThreads();
00085     
00086     LOGPRINTF("XinitThreads returned");
00087     
00088     // install custom error handler to avoid X's default fatal errors
00089     XSetErrorHandler(on_x_error);
00090     
00091     // set display globally
00092     g_display = gdk_x11_get_default_xdisplay();
00093 
00094     // set atoms globally
00095     atom_client_list   = XInternAtom(g_display, "_NET_CLIENT_LIST", False);
00096     atom_active_window = XInternAtom(g_display, "_NET_ACTIVE_WINDOW", False);
00097     atom_wm_user_time  = XInternAtom(g_display, "_NET_WM_USER_TIME", False);
00098 }

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  doxygen 1.6.2-20100208