Skip to content

Commit

Permalink
Add geometry flag
Browse files Browse the repository at this point in the history
  • Loading branch information
baskerville committed Feb 2, 2014
1 parent 9c5c779 commit e96c1b1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
10 changes: 8 additions & 2 deletions doc/xwinfo.1
Expand Up @@ -2,12 +2,12 @@
.\" Title: xwinfo
.\" Author: [see the "Author" section]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
.\" Date: 11/04/2013
.\" Date: 02/02/2014
.\" Manual: Xwinfo Manual
.\" Source: Xwinfo 0.1
.\" Language: English
.\"
.TH "XWINFO" "1" "11/04/2013" "Xwinfo 0\&.1" "Xwinfo Manual"
.TH "XWINFO" "1" "02/02/2014" "Xwinfo 0\&.1" "Xwinfo Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -71,6 +71,12 @@ Print the window type\&.
.RS 4
Print the window state\&.
.RE
.PP
\fB\-g\fR
.RS 4
Print the geometry (as
\fIwidth height x y\fR)\&.
.RE
.SH "AUTHOR"
.sp
Bastien Dejean <nihilhill at gmail\&.com>
3 changes: 3 additions & 0 deletions doc/xwinfo.1.txt
Expand Up @@ -44,6 +44,9 @@ Options
*-s*::
Print the window state.

*-g*::
Print the geometry (as 'width height x y').

Author
------

Expand Down
15 changes: 14 additions & 1 deletion xwinfo.c
Expand Up @@ -16,7 +16,7 @@ int main(int argc, char *argv[])
unsigned int mask = 0;
char opt;

while ((opt = getopt(argc, argv, "hvcints")) != -1) {
while ((opt = getopt(argc, argv, "hvcintsg")) != -1) {
switch (opt) {
case 'h':
printf("xwinfo OPTIONS [WID ...]\n");
Expand All @@ -41,6 +41,9 @@ int main(int argc, char *argv[])
case 's':
mask |= WINDOW_STATE;
break;
case 'g':
mask |= GEOMETRY;
break;
}
}

Expand Down Expand Up @@ -96,6 +99,8 @@ void process_window(xcb_window_t win, unsigned int mask, struct wm_cookies *cook
cookies->window_type = xcb_ewmh_get_wm_window_type(ewmh, win);
if (mask & WINDOW_STATE)
cookies->window_state = xcb_ewmh_get_wm_state(ewmh, win);
if (mask & GEOMETRY)
cookies->geometry = xcb_get_geometry(dpy, win);
if (mask & (CLASS_NAME | INSTANCE_NAME)) {
xcb_icccm_get_wm_class_reply_t reply;
if (xcb_icccm_get_wm_class_reply(dpy, cookies->class_instance, &reply, NULL) == 1) {
Expand Down Expand Up @@ -160,6 +165,14 @@ void process_window(xcb_window_t win, unsigned int mask, struct wm_cookies *cook
printf("%s\n", MISSING_VALUE);
}
}
if (mask & GEOMETRY) {
xcb_get_geometry_reply_t *reply = xcb_get_geometry_reply(dpy, cookies->geometry, NULL);
if (reply != NULL)
printf("%u %u %i %i\n", reply->width, reply->height, reply->x, reply->y);
else
printf("%s %s %s %s\n", MISSING_VALUE, MISSING_VALUE, MISSING_VALUE, MISSING_VALUE);
}

}

void print_type_atom(xcb_atom_t a)
Expand Down
2 changes: 2 additions & 0 deletions xwinfo.h
Expand Up @@ -9,6 +9,7 @@ struct wm_cookies {
xcb_get_property_cookie_t ewmh_name;
xcb_get_property_cookie_t window_type;
xcb_get_property_cookie_t window_state;
xcb_get_geometry_cookie_t geometry;
};

enum {
Expand All @@ -17,6 +18,7 @@ enum {
WINDOW_NAME = 4,
WINDOW_TYPE = 8,
WINDOW_STATE = 16,
GEOMETRY = 32,
};

xcb_connection_t *dpy;
Expand Down

0 comments on commit e96c1b1

Please sign in to comment.