diff -urbBw wmctrl-1.07/main.c wmctrl-1.07.patched/main.c --- wmctrl-1.07/main.c 2005-01-28 19:31:33.000000000 -0800 +++ wmctrl-1.07.patched/main.c 2008-07-20 11:45:34.000000000 -0700 @@ -65,6 +65,7 @@ " -r -N Set the name (long title) of the window.\n" \ " -r -I Set the icon name (short title) of the window.\n" \ " -r -T Set both the name and the icon name of the window.\n" \ +" -r -L List information about the window.\n" \ " -k (on|off) Activate or deactivate window manager's\n" \ " \"showing the desktop\" mode. Many window managers\n" \ " do not implement this mode.\n" \ @@ -217,6 +218,7 @@ Atom xa_prop_type, gchar *prop_name, unsigned long *size); static void init_charset(void); static int window_move_resize (Display *disp, Window win, char *arg); +static void display_window (Display *disp, Window win, int max_client_machine_len); static int window_state (Display *disp, Window win, char *arg); static Window Select_Window(Display *dpy); static Window get_active_window(Display *dpy); @@ -264,7 +266,7 @@ } } - while ((opt = getopt(argc, argv, "FGVvhlupidmxa:r:s:c:t:w:k:o:n:g:e:b:N:I:T:R:")) != -1) { + while ((opt = getopt(argc, argv, "FGVvhlupidmxa:r:s:c:t:w:k:o:n:g:e:b:N:I:T:LR:")) != -1) { missing_option = 0; switch (opt) { case 'F': @@ -296,7 +298,7 @@ case 'r': options.param_window = optarg; break; - case 't': case 'e': case 'b': case 'N': case 'I': case 'T': + case 't': case 'e': case 'b': case 'N': case 'I': case 'T': case 'L': options.param = optarg; action = opt; break; @@ -356,7 +358,7 @@ ret = wm_info(disp); break; case 'a': case 'c': case 'R': - case 't': case 'e': case 'b': case 'N': case 'I': case 'T': + case 't': case 'e': case 'b': case 'N': case 'I': case 'T': case 'L': if (! options.param_window) { fputs("No window was specified.\n", stderr); return EXIT_FAILURE; @@ -874,6 +876,69 @@ } }/*}}}*/ +static void display_window (Display *disp, Window win, int max_client_machine_len) {/*{{{*/ + gchar *title_utf8 = get_window_title(disp, win); /* UTF8 */ + gchar *title_out = get_output_str(title_utf8, TRUE); + gchar *client_machine; + gchar *class_out = get_window_class(disp, win); /* UTF8 */ + unsigned long *pid; + unsigned long *desktop; + int x, y, junkx, junky; + unsigned int wwidth, wheight, bw, depth; + Window junkroot; + + /* desktop ID */ + if ((desktop = (unsigned long *)get_property(disp, win, + XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) { + desktop = (unsigned long *)get_property(disp, win, + XA_CARDINAL, "_WIN_WORKSPACE", NULL); + } + + /* client machine */ + client_machine = get_property(disp, win, + XA_STRING, "WM_CLIENT_MACHINE", NULL); + + /* pid */ + pid = (unsigned long *)get_property(disp, win, + XA_CARDINAL, "_NET_WM_PID", NULL); + + /* geometry */ + XGetGeometry (disp, win, &junkroot, &junkx, &junky, + &wwidth, &wheight, &bw, &depth); + XTranslateCoordinates (disp, win, junkroot, junkx, junky, + &x, &y, &junkroot); + + /* special desktop ID -1 means "all desktops", so we + have to convert the desktop value to signed long */ + printf("0x%.8lx %2ld", win, + desktop ? (signed long)*desktop : 0); + if (options.show_pid) { + printf(" %-6lu", pid ? *pid : 0); + } + if (options.show_geometry) { + printf(" %-4d %-4d %-4d %-4d", x, y, wwidth, wheight); + } + if (options.show_class) { + printf(" %-20s ", class_out ? class_out : "N/A"); + } + + if (max_client_machine_len == 0) { + max_client_machine_len = strlen(client_machine); + } + + printf(" %*s %s\n", + max_client_machine_len, + client_machine ? client_machine : "N/A", + title_out ? title_out : "N/A" + ); + g_free(title_utf8); + g_free(title_out); + g_free(desktop); + g_free(client_machine); + g_free(class_out); + g_free(pid); +}/*}}}*/ + static int action_window (Display *disp, Window win, char mode) {/*{{{*/ p_verbose("Using window: 0x%.8lx\n", win); switch (mode) { @@ -883,6 +948,10 @@ case 'c': return close_window(disp, win); + case 'L': + display_window(disp, win, 0); + return EXIT_SUCCESS; + case 'e': /* resize/move the window around the desktop => -r -e */ return window_move_resize(disp, win, options.param); @@ -1297,62 +1366,7 @@ /* print the list */ for (i = 0; i < client_list_size / sizeof(Window); i++) { - gchar *title_utf8 = get_window_title(disp, client_list[i]); /* UTF8 */ - gchar *title_out = get_output_str(title_utf8, TRUE); - gchar *client_machine; - gchar *class_out = get_window_class(disp, client_list[i]); /* UTF8 */ - unsigned long *pid; - unsigned long *desktop; - int x, y, junkx, junky; - unsigned int wwidth, wheight, bw, depth; - Window junkroot; - - /* desktop ID */ - if ((desktop = (unsigned long *)get_property(disp, client_list[i], - XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) { - desktop = (unsigned long *)get_property(disp, client_list[i], - XA_CARDINAL, "_WIN_WORKSPACE", NULL); - } - - /* client machine */ - client_machine = get_property(disp, client_list[i], - XA_STRING, "WM_CLIENT_MACHINE", NULL); - - /* pid */ - pid = (unsigned long *)get_property(disp, client_list[i], - XA_CARDINAL, "_NET_WM_PID", NULL); - - /* geometry */ - XGetGeometry (disp, client_list[i], &junkroot, &junkx, &junky, - &wwidth, &wheight, &bw, &depth); - XTranslateCoordinates (disp, client_list[i], junkroot, junkx, junky, - &x, &y, &junkroot); - - /* special desktop ID -1 means "all desktops", so we - have to convert the desktop value to signed long */ - printf("0x%.8lx %2ld", client_list[i], - desktop ? (signed long)*desktop : 0); - if (options.show_pid) { - printf(" %-6lu", pid ? *pid : 0); - } - if (options.show_geometry) { - printf(" %-4d %-4d %-4d %-4d", x, y, wwidth, wheight); - } - if (options.show_class) { - printf(" %-20s ", class_out ? class_out : "N/A"); - } - - printf(" %*s %s\n", - max_client_machine_len, - client_machine ? client_machine : "N/A", - title_out ? title_out : "N/A" - ); - g_free(title_utf8); - g_free(title_out); - g_free(desktop); - g_free(client_machine); - g_free(class_out); - g_free(pid); + display_window(disp, client_list[i], max_client_machine_len); } g_free(client_list);