From bb2f0d8b837f4829d9f5d24d33f9f81097250ebc Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sat, 27 Feb 2016 21:55:43 +0100 Subject: Move more to xcb, window_*_ functions to xcb_ functions --- source/dialogs/window.c | 45 +++++++++++++++++++++++++++++++++++---------- source/i3-support.c | 2 +- source/view.c | 2 +- source/x11-helper.c | 19 ++++--------------- 4 files changed, 41 insertions(+), 27 deletions(-) (limited to 'source') diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 4eb4bf1b..08dd4a8e 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,10 @@ #define CLIENTWINDOWTYPE 10 #define CLIENTROLE 50 +extern xcb_connection_t *xcb_connection; +extern xcb_ewmh_connection_t xcb_ewmh; extern xcb_screen_t *xcb_screen; +extern int xcb_screen_nbr; // a manageable window typedef struct { @@ -272,9 +276,17 @@ static client* window_client ( Display *display, Window win ) memmove ( &c->xattr, attr, sizeof ( XWindowAttributes ) ); XGetTransientForHint ( display, win, &c->trans ); - c->states = window_get_atom_prop ( display, win, netatoms[_NET_WM_STATE], c->state, CLIENTSTATE ); - - c->window_types = window_get_atom_prop ( display, win, netatoms[_NET_WM_WINDOW_TYPE], c->window_type, CLIENTWINDOWTYPE ); + xcb_get_property_cookie_t cky = xcb_ewmh_get_wm_state(&xcb_ewmh, win); + xcb_ewmh_get_atoms_reply_t states; + if(xcb_ewmh_get_wm_state_reply( &xcb_ewmh, cky, &states, NULL)){ + c->states = MIN(CLIENTSTATE,states.atoms_len); + memcpy(c->state, states.atoms, MIN(CLIENTSTATE, states.atoms_len)); + } + cky = xcb_ewmh_get_wm_window_type(&xcb_ewmh, win); + if(xcb_ewmh_get_wm_window_type_reply( &xcb_ewmh, cky, &states, NULL)){ + c->window_types= MIN(CLIENTWINDOWTYPE,states.atoms_len); + memcpy(c->window_type, states.atoms, MIN(CLIENTWINDOWTYPE, states.atoms_len)); + } char *name; if ( ( name = window_get_text_prop ( display, c->window, netatoms[_NET_WM_NAME] ) ) && name ) { @@ -399,8 +411,9 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) } // Get the current desktop. - unsigned long current_desktop = 0; - if ( !window_get_cardinal_prop ( display, root, netatoms[_NET_CURRENT_DESKTOP], ¤t_desktop, 1 ) ) { + unsigned int current_desktop = 0; + xcb_get_property_cookie_t c = xcb_ewmh_get_current_desktop( &xcb_ewmh, xcb_screen_nbr); + if ( !xcb_ewmh_get_current_desktop_reply ( &xcb_ewmh, c, ¤t_desktop, NULL )){ current_desktop = 0; } @@ -418,7 +431,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) char pattern[50]; int i; unsigned int classfield = 0; - unsigned long desktops = 0; + unsigned int desktops = 0; // windows we actually display. May be slightly different to _NET_CLIENT_LIST_STACKING // if we happen to have a window destroyed while we're working... pd->ids = winlist_new (); @@ -450,9 +463,11 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) } // Create pattern for printing the line. - if ( !window_get_cardinal_prop ( display, root, netatoms[_NET_NUMBER_OF_DESKTOPS], &desktops, 1 ) ) { - desktops = 1; + xcb_get_property_cookie_t c = xcb_ewmh_get_number_of_desktops( &xcb_ewmh, xcb_screen_nbr); + if ( !xcb_ewmh_get_number_of_desktops_reply ( &xcb_ewmh, c, &desktops, NULL )){ + desktops= 1; } + if ( pd->config_i3_mode ) { snprintf ( pattern, 50, "%%-%ds %%s", MAX ( 5, classfield ) ); } @@ -469,21 +484,31 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) if ( ( c = window_client ( display, w ) ) ) { // final line format - unsigned long wmdesktop; + unsigned int wmdesktop; char desktop[5]; desktop[0] = 0; size_t len = strlen ( c->title ) + strlen ( c->class ) + classfield + 50; char *line = g_malloc ( len ); if ( !pd->config_i3_mode ) { // find client's desktop. - if ( !window_get_cardinal_prop ( display, c->window, netatoms[_NET_WM_DESKTOP], &wmdesktop, 1 ) ) { + xcb_get_property_cookie_t cookie; + xcb_get_property_reply_t *r; + + cookie = xcb_get_property(xcb_connection, 0, c->window, xcb_ewmh._NET_WM_DESKTOP, XCB_GET_PROPERTY, 0, sizeof(unsigned int)); + r = xcb_get_property_reply(xcb_connection, cookie, NULL); + if ( r->type == XCB_ATOM_INTEGER){ + wmdesktop = *((int *)xcb_get_property_value(r)); + } + if ( r->type != XCB_ATOM_INTEGER) { // Assume the client is on all desktops. wmdesktop = 0xFFFFFFFF; } else if ( cd && wmdesktop != current_desktop ) { g_free ( line ); + free(r); continue; } + free(r); if ( wmdesktop < 0xFFFFFFFF ) { snprintf ( desktop, 5, "%d", (int) wmdesktop ); diff --git a/source/i3-support.c b/source/i3-support.c index 02ee548f..c3a10594 100644 --- a/source/i3-support.c +++ b/source/i3-support.c @@ -150,7 +150,7 @@ void i3_support_free_internals ( void ) { } -int i3_support_initialize ( Display *display ) +int i3_support_initialize ( Display *display, xcb_connection_t *xcb_connection ) { return FALSE; } diff --git a/source/view.c b/source/view.c index b0d52ce5..615c57bc 100644 --- a/source/view.c +++ b/source/view.c @@ -559,7 +559,7 @@ static Window __create_window ( xcb_connection_t *xcb_connection, xcb_screen_t * xcb_change_property ( xcb_connection, XCB_PROP_MODE_REPLACE, box, xcb_ewmh._NET_WM_NAME, xcb_ewmh.UTF8_STRING, 8, 4,"rofi"); xcb_change_property ( xcb_connection, XCB_PROP_MODE_REPLACE, box, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, 4,"rofi"); - x11_set_window_opacity ( display, box, config.window_opacity ); + x11_set_window_opacity ( xcb_connection, box, config.window_opacity ); return box; } diff --git a/source/x11-helper.c b/source/x11-helper.c index 68756db9..c4f63a79 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -147,23 +147,12 @@ char* window_get_text_prop ( Display *display, Window w, Atom atom ) return res; } -int window_get_atom_prop ( Display *display, Window w, Atom atom, Atom *list, int count ) -{ - Atom type; - int items; - return window_get_prop ( display, w, atom, &type, &items, list, count * sizeof ( Atom ) ) && type == XA_ATOM ? items : 0; -} void window_set_atom_prop ( xcb_connection_t *xcb_connection, Window w, xcb_atom_t prop, xcb_atom_t *atoms, int count ) { xcb_change_property ( xcb_connection, XCB_PROP_MODE_REPLACE, w, prop, XCB_ATOM_ATOM, 32, count, atoms); } -int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned long *list, int count ) -{ - Atom type; int items; - return window_get_prop ( display, w, atom, &type, &items, list, count * sizeof ( unsigned long ) ) && type == XA_CARDINAL ? items : 0; -} extern xcb_screen_t *xcb_screen; extern int xcb_screen_nbr; int monitor_get_smallest_size ( xcb_connection_t *xcb_connection ) @@ -534,13 +523,13 @@ void x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key ) *key = sym; } -void x11_set_window_opacity ( Display *display, Window box, unsigned int opacity ) +void x11_set_window_opacity ( xcb_connection_t *xcb_connection, Window box, unsigned int opacity ) { // Scale 0-100 to 0 - UINT32_MAX. unsigned int opacity_set = ( unsigned int ) ( ( opacity / 100.0 ) * UINT32_MAX ); - // Set opacity. - XChangeProperty ( display, box, netatoms[_NET_WM_WINDOW_OPACITY], XA_CARDINAL, 32, PropModeReplace, - ( unsigned char * ) &opacity_set, 1L ); + + xcb_change_property( xcb_connection, XCB_PROP_MODE_REPLACE, box, + netatoms[_NET_WM_WINDOW_OPACITY], XCB_ATOM_CARDINAL, 32, 1L, &opacity_set); } /** -- cgit v1.2.3