#include "config.h"
#include <glib.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <stdio.h>
#include <libmb/mbutil.h>
#include "log.h"
Go to the source code of this file.
Defines | |
#define | RETURN_NONE_IF_NULL(p) if ((p) == '\0') return None; |
Functions | |
static Window | single_instance_get_window (Display *dpy, const char *bin_name) |
int | main (int argc, char *argv[]) |
#define RETURN_NONE_IF_NULL | ( | p | ) | if ((p) == '\0') return None; |
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 50 of file wmtest.c.
References LOGPRINTF, and single_instance_get_window().
00051 { 00052 LOGPRINTF("entry"); 00053 00054 Window win_found; 00055 Display *display; 00056 00057 g_type_init(); 00058 gtk_init(&argc, &argv); 00059 00060 LOGPRINTF("default screen = %d", gdk_x11_get_default_screen()); 00061 00062 LOGPRINTF("get display"); 00063 display = gdk_x11_get_default_xdisplay(); 00064 LOGPRINTF("display = %p", display); 00065 00066 LOGPRINTF("get window: %s", argv[1]); 00067 win_found = single_instance_get_window (display, argv[1]); 00068 00069 if (win_found != None) 00070 { 00071 LOGPRINTF("window found and activated!"); 00072 // mb_util_window_activate(display, win_found); 00073 } 00074 else 00075 { 00076 LOGPRINTF("window not found"); 00077 } 00078 00079 return 0; 00080 }
static Window single_instance_get_window | ( | Display * | dpy, | |
const char * | bin_name | |||
) | [static] |
Definition at line 83 of file wmtest.c.
References data, and LOGPRINTF.
Referenced by main().
00084 { 00085 /* XXX Should really set this on init rather than every time */ 00086 Atom atom_exec_map = XInternAtom(dpy, "_NET_CLIENT_LIST", False); 00087 LOGPRINTF("entry"); 00088 00089 Atom type; 00090 int format; 00091 unsigned char *data = NULL; 00092 unsigned long n_items, bytes_after; 00093 int result; 00094 int i; 00095 XClassHint hint; 00096 00097 LOGPRINTF("enter"); 00098 00099 Atom atom_net_get_active = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False); 00100 00101 result = XGetWindowProperty(dpy, RootWindow(dpy, DefaultScreen(dpy)), 00102 atom_net_get_active, 00103 0, 10000L, 00104 False, XA_WINDOW, 00105 &type, &format, &n_items, 00106 &bytes_after, (unsigned char **)&data); 00107 00108 00109 if (result != Success || data == NULL || n_items == 0) 00110 { 00111 if (data) XFree(data); 00112 LOGPRINTF("failed to get windowproperty 1. result = %d, data = %p, items = %ld", result, data, n_items); 00113 return None; 00114 } 00115 00116 if (XGetClassHint(dpy, ((Window*)data)[0], &hint)) 00117 { 00118 LOGPRINTF("Active window %s, %s", hint.res_name, hint.res_class); 00119 } 00120 00121 result = XGetWindowProperty(dpy, RootWindow(dpy, DefaultScreen(dpy)), 00122 atom_exec_map, 00123 0, 10000L, 00124 False, XA_WINDOW, 00125 &type, &format, &n_items, 00126 &bytes_after, (unsigned char **)&data); 00127 00128 if (result != Success || data == NULL || n_items == 0) 00129 { 00130 if (data) XFree(data); 00131 LOGPRINTF("failed to get windowproperty 2. result = %d, data = %p, items = %ld", result, data, n_items); 00132 return None; 00133 } 00134 00135 for (i = 0; i < n_items; i++) 00136 { 00137 if (XGetClassHint(dpy, ((Window*)data)[i], &hint)) 00138 { 00139 LOGPRINTF("Window [%d] window:%d, class: %s, name: %s", i, (guint) ((Window*)data)[i], hint.res_name, hint.res_class); 00140 00141 if (strcmp(hint.res_name, bin_name) == 0) 00142 { 00143 LOGPRINTF("Found and activated %s",bin_name); 00144 // mb_util_window_activate(dpy, ((Window*)data)[i]); 00145 00146 Atom atom_net_active = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False); 00147 XEvent ev; 00148 00149 memset(&ev, 0, sizeof ev); 00150 ev.xclient.type = ClientMessage; 00151 ev.xclient.window = ((Window*)data)[i]; 00152 ev.xclient.message_type = atom_net_active; 00153 ev.xclient.format = 32; 00154 00155 ev.xclient.data.l[0] = 1; 00156 int retval; 00157 retval = XSendEvent(dpy, RootWindow(dpy, DefaultScreen(dpy)), False, SubstructureRedirectMask, &ev); 00158 00159 LOGPRINTF("XSendEvent returned %d", retval); 00160 00161 return ((Window*)data)[i]; 00162 } 00163 } 00164 } 00165 00166 XFree (data); 00167 00168 return None; 00169 }