summaryrefslogtreecommitdiff
path: root/hidden.c
diff options
context:
space:
mode:
authorMichael Cardell Widerkrantz <mc@hack.org>2012-03-09 15:41:30 +0100
committerMichael Cardell Widerkrantz <mc@hack.org>2012-03-09 15:41:30 +0100
commita6e3cd2dc7485bec4a84bc2ee4694030849fb3d2 (patch)
treeb795b0b30600341dfe0246526fe4ec6e17b42575 /hidden.c
parentd29aae229b96de7d33d9887ec3784cb2f1b3cd67 (diff)
downloadmcwm-a6e3cd2dc7485bec4a84bc2ee4694030849fb3d2.zip
Added option -c to print title:xdotool command. Useful for combining
with 9menu and similar menu programs.
Diffstat (limited to 'hidden.c')
-rw-r--r--hidden.c55
1 files changed, 46 insertions, 9 deletions
diff --git a/hidden.c b/hidden.c
index c86bedb..251025c 100644
--- a/hidden.c
+++ b/hidden.c
@@ -1,5 +1,4 @@
/*
- *
* hidden - A small program to listen all windows with WM_STATE set to
* Iconic.
*
@@ -22,6 +21,7 @@
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
+#include <getopt.h>
#include <xcb/xcb.h>
#include <xcb/xcb_icccm.h>
@@ -31,11 +31,14 @@ xcb_screen_t *screen;
xcb_atom_t wm_state;
xcb_atom_t wm_icon_name;
+bool printcommand = false;
+
static uint32_t get_wm_state(xcb_drawable_t win);
static int findhidden(void);
static void init(void);
static void cleanup(void);
static xcb_atom_t getatom(char *atom_name);
+static void printhelp(void);
uint32_t get_wm_state(xcb_drawable_t win)
{
@@ -123,15 +126,24 @@ int findhidden(void)
/*
* Example names:
*
- * _NET_WM_ICON_NAME(UTF8_STRING) = 0x75, 0x72, 0x78, 0x76, 0x74
- * WM_ICON_NAME(STRING) = "urxvt"
- * _NET_WM_NAME(UTF8_STRING) = 0x75, 0x72, 0x78, 0x76, 0x74
- * WM_NAME(STRING) = "urxvt"
+ * _NET_WM_ICON_NAME(UTF8_STRING) = 0x75, 0x72, 0x78,
+ * 0x76, 0x74 WM_ICON_NAME(STRING) = "urxvt"
+ * _NET_WM_NAME(UTF8_STRING) = 0x75, 0x72, 0x78, 0x76,
+ * 0x74 WM_NAME(STRING) = "urxvt"
*/
cookie = xcb_icccm_get_wm_icon_name(conn, children[i]);
xcb_icccm_get_wm_icon_name_reply(conn, cookie, &prop, &error);
- puts(prop.name);
+ prop.name[prop.name_len] = '\0';
+ if (printcommand)
+ {
+ printf("'%s':'xdotool windowmap 0x%x windowraise 0x%x'\n",
+ prop.name, children[i], children[i]);
+ }
+ else
+ {
+ puts(prop.name);
+ }
}
} /* if not override redirect */
@@ -202,13 +214,38 @@ xcb_atom_t getatom(char *atom_name)
return 0;
}
-int main(void)
+void printhelp(void)
{
+ printf("hidden: Usage: hidden [-c]\n");
+ printf(" -c print 9menu/xdotool compatible output.\n");
+}
- init();
+int main(int argc, char **argv)
+{
+ int ch; /* Option character */
+ while (1)
+ {
+ ch = getopt(argc, argv, "c");
+ if (-1 == ch)
+ {
+ /* No more options, break out of while loop. */
+ break;
+ }
+ switch (ch)
+ {
+ case 'c':
+ printcommand = true;
+ break;
+
+ default:
+ printhelp();
+ exit(0);
+ } /* switch ch */
+ } /* while 1 */
+
+ init();
wm_state = getatom("WM_STATE");
-
findhidden();
cleanup();
exit(0);