diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-02-28 15:32:53 +0100 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-02-28 15:32:53 +0100 |
commit | a4fd907fe869daaef2726366972519371ac6e358 (patch) | |
tree | 0de3b2e3d6c477538581bb3f9c2d71e3f598261c | |
parent | 6fb94876ca35bb94ab92c6ee2ea26d0c1b15da9d (diff) |
Run indenter
-rw-r--r-- | include/helper.h | 2 | ||||
-rw-r--r-- | include/x11-helper.h | 6 | ||||
-rw-r--r-- | source/dialogs/window.c | 158 | ||||
-rw-r--r-- | source/helper.c | 8 | ||||
-rw-r--r-- | source/i3-support.c | 4 | ||||
-rw-r--r-- | source/rofi.c | 58 | ||||
-rw-r--r-- | source/view.c | 93 | ||||
-rw-r--r-- | source/x11-helper.c | 217 | ||||
-rw-r--r-- | source/xrmoptions.c | 6 | ||||
-rw-r--r-- | test/helper-test.c | 4 | ||||
-rw-r--r-- | test/textbox-test.c | 10 |
11 files changed, 282 insertions, 284 deletions
diff --git a/include/helper.h b/include/helper.h index 6caf2ed2..d479ce92 100644 --- a/include/helper.h +++ b/include/helper.h @@ -137,7 +137,7 @@ void remove_pid_file ( int fd ); * * This functions exits the program with 1 when it finds an invalid configuration. */ -int config_sanity_check ( xcb_connection_t *xcb_connection); +int config_sanity_check ( xcb_connection_t *xcb_connection ); /** * @param arg string to parse. diff --git a/include/x11-helper.h b/include/x11-helper.h index 7f91b9b7..d6479bc6 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -32,9 +32,9 @@ void window_set_atom_prop ( xcb_connection_t *xcb_connection, xcb_window_t w, xc #define ATOM_CHAR( x ) # x // usable space on a monitor -#define EWMH_ATOMS( X ) \ - X ( _NET_WM_WINDOW_OPACITY ), \ - X ( I3_SOCKET_PATH ), \ +#define EWMH_ATOMS( X ) \ + X ( _NET_WM_WINDOW_OPACITY ), \ + X ( I3_SOCKET_PATH ), \ X ( WM_WINDOW_ROLE ) enum { EWMH_ATOMS ( ATOM_ENUM ), NUM_NETATOMS }; diff --git a/source/dialogs/window.c b/source/dialogs/window.c index ccdf9824..9c36bcbf 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -54,34 +54,34 @@ #define CLIENTWINDOWTYPE 10 #define CLIENTROLE 50 -extern xcb_connection_t *xcb_connection; +extern xcb_connection_t *xcb_connection; extern xcb_ewmh_connection_t xcb_ewmh; -extern xcb_screen_t *xcb_screen; -extern int xcb_screen_nbr; +extern xcb_screen_t *xcb_screen; +extern int xcb_screen_nbr; // a manageable window typedef struct { - xcb_window_t window; + xcb_window_t window; xcb_get_window_attributes_reply_t xattr; - char *title; - char *class; - char *name; - char *role; - int states; - xcb_atom_t state[CLIENTSTATE]; - int window_types; - xcb_atom_t window_type[CLIENTWINDOWTYPE]; - int active; - int demands; - long hint_flags; + char *title; + char *class; + char *name; + char *role; + int states; + xcb_atom_t state[CLIENTSTATE]; + int window_types; + xcb_atom_t window_type[CLIENTWINDOWTYPE]; + int active; + int demands; + long hint_flags; } client; // window lists typedef struct { xcb_window_t *array; - client **data; - int len; + client **data; + int len; } winlist; winlist *cache_client = NULL; @@ -207,9 +207,8 @@ static void x11_cache_free ( void ) */ static xcb_get_window_attributes_reply_t * window_get_attributes ( xcb_connection_t *xcb_connection, xcb_window_t w ) { - - xcb_get_window_attributes_cookie_t c = xcb_get_window_attributes(xcb_connection, w); - xcb_get_window_attributes_reply_t *r = xcb_get_window_attributes_reply ( xcb_connection, c, NULL); + xcb_get_window_attributes_cookie_t c = xcb_get_window_attributes ( xcb_connection, w ); + xcb_get_window_attributes_reply_t *r = xcb_get_window_attributes_reply ( xcb_connection, c, NULL ); if ( r ) { return r; } @@ -261,38 +260,37 @@ static client* window_client ( xcb_connection_t *xcb_connection, xcb_window_t wi // copy xattr so we don't have to care when stuff is freed memmove ( &c->xattr, attr, sizeof ( xcb_get_window_attributes_reply_t ) ); - - xcb_get_property_cookie_t cky = xcb_ewmh_get_wm_state(&xcb_ewmh, win); + 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)); - xcb_ewmh_get_atoms_reply_wipe(&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 ) ); + xcb_ewmh_get_atoms_reply_wipe ( &states ); } - 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)); - xcb_ewmh_get_atoms_reply_wipe(&states); + 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 ) ); + xcb_ewmh_get_atoms_reply_wipe ( &states ); } c->title = window_get_text_prop ( xcb_connection, c->window, xcb_ewmh._NET_WM_NAME ); if ( c->title == NULL ) { - c->title = window_get_text_prop ( xcb_connection, c->window, XCB_ATOM_WM_NAME); + c->title = window_get_text_prop ( xcb_connection, c->window, XCB_ATOM_WM_NAME ); } c->role = window_get_text_prop ( xcb_connection, c->window, netatoms[WM_WINDOW_ROLE] ); cky = xcb_icccm_get_wm_class ( xcb_connection, c->window ); xcb_icccm_get_wm_class_reply_t wcr; - if ( xcb_icccm_get_wm_class_reply (xcb_connection, cky, &wcr, NULL)) { - c->class = g_strdup(wcr.class_name); - xcb_icccm_get_wm_class_reply_wipe (&wcr); + if ( xcb_icccm_get_wm_class_reply ( xcb_connection, cky, &wcr, NULL ) ) { + c->class = g_strdup ( wcr.class_name ); + xcb_icccm_get_wm_class_reply_wipe ( &wcr ); } - xcb_get_property_cookie_t cc = xcb_icccm_get_wm_hints ( xcb_connection, c->window); - xcb_icccm_wm_hints_t r; - if (xcb_icccm_get_wm_hints_reply ( xcb_connection, cc, &r, NULL)){ + xcb_get_property_cookie_t cc = xcb_icccm_get_wm_hints ( xcb_connection, c->window ); + xcb_icccm_wm_hints_t r; + if ( xcb_icccm_get_wm_hints_reply ( xcb_connection, cc, &r, NULL ) ) { c->hint_flags = r.flags; } @@ -365,48 +363,48 @@ static unsigned int window_mode_get_num_entries ( const Mode *sw ) } static void _window_mode_load_data ( Mode *sw, unsigned int cd ) { - ModeModePrivateData *pd = (ModeModePrivateData *) mode_get_private_data ( sw ); + ModeModePrivateData *pd = (ModeModePrivateData *) mode_get_private_data ( sw ); // find window list int nwins = 0; - xcb_window_t wins[100]; - xcb_window_t curr_win_id; + xcb_window_t wins[100]; + xcb_window_t curr_win_id; // Create cache x11_cache_create (); // Check for i3 pd->config_i3_mode = i3_support_initialize ( xcb_connection ); - xcb_get_property_cookie_t c =xcb_ewmh_get_active_window( &xcb_ewmh, xcb_screen_nbr); - if ( !xcb_ewmh_get_active_window_reply ( &xcb_ewmh, c, &curr_win_id, NULL )) { + xcb_get_property_cookie_t c = xcb_ewmh_get_active_window ( &xcb_ewmh, xcb_screen_nbr ); + if ( !xcb_ewmh_get_active_window_reply ( &xcb_ewmh, c, &curr_win_id, NULL ) ) { curr_win_id = 0; } // Get the current desktop. unsigned int current_desktop = 0; - c = xcb_ewmh_get_current_desktop( &xcb_ewmh, xcb_screen_nbr); - if ( !xcb_ewmh_get_current_desktop_reply ( &xcb_ewmh, c, ¤t_desktop, NULL )){ + 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; } - c = xcb_ewmh_get_client_list_stacking ( &xcb_ewmh, 0); + c = xcb_ewmh_get_client_list_stacking ( &xcb_ewmh, 0 ); xcb_ewmh_get_windows_reply_t clients; - if ( xcb_ewmh_get_client_list_stacking_reply ( &xcb_ewmh, c, &clients, NULL)){ - nwins = MIN ( 100, clients.windows_len); - memcpy(wins, clients.windows, nwins*sizeof(xcb_window_t) ); - xcb_ewmh_get_windows_reply_wipe(&clients); + if ( xcb_ewmh_get_client_list_stacking_reply ( &xcb_ewmh, c, &clients, NULL ) ) { + nwins = MIN ( 100, clients.windows_len ); + memcpy ( wins, clients.windows, nwins * sizeof ( xcb_window_t ) ); + xcb_ewmh_get_windows_reply_wipe ( &clients ); } else { - c = xcb_ewmh_get_client_list ( &xcb_ewmh, xcb_screen_nbr); - if ( xcb_ewmh_get_client_list_reply ( &xcb_ewmh, c, &clients, NULL)) { - nwins = MIN ( 100, clients.windows_len); - memcpy(wins, clients.windows, nwins*sizeof(xcb_window_t) ); - xcb_ewmh_get_windows_reply_wipe(&clients); + c = xcb_ewmh_get_client_list ( &xcb_ewmh, xcb_screen_nbr ); + if ( xcb_ewmh_get_client_list_reply ( &xcb_ewmh, c, &clients, NULL ) ) { + nwins = MIN ( 100, clients.windows_len ); + memcpy ( wins, clients.windows, nwins * sizeof ( xcb_window_t ) ); + xcb_ewmh_get_windows_reply_wipe ( &clients ); } } if ( nwins > 0 ) { - char pattern[50]; - int i; - unsigned int classfield = 0; - unsigned int desktops = 0; + char pattern[50]; + int i; + unsigned int classfield = 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 (); @@ -425,7 +423,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) if ( client_has_state ( c, xcb_ewmh._NET_WM_STATE_DEMANDS_ATTENTION ) ) { c->demands = TRUE; } - if ( ( c->hint_flags & XCB_ICCCM_WM_HINT_X_URGENCY ) != 0) { + if ( ( c->hint_flags & XCB_ICCCM_WM_HINT_X_URGENCY ) != 0 ) { c->demands = TRUE; } @@ -437,9 +435,9 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) } // Create pattern for printing the line. - 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; + 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 ) { @@ -454,36 +452,38 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) // build the actual list for ( i = 0; i < ( pd->ids->len ); i++ ) { xcb_window_t w = pd->ids->array[i]; - client *c; + client *c; if ( ( c = window_client ( xcb_connection, w ) ) ) { // final line format unsigned int wmdesktop; - char desktop[5]; + char desktop[5]; desktop[0] = 0; - size_t len = + size_t len = ( ( c->title != NULL ) ? strlen ( c->title ) : 0 ) + ( c->class ? strlen ( c->class ) : 0 ) + classfield + 50; - char *line = g_malloc ( len ); + char *line = g_malloc ( len ); if ( !pd->config_i3_mode ) { // find client's desktop. 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&& r->type == XCB_ATOM_INTEGER){ - wmdesktop = *((int *)xcb_get_property_value(r)); + 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 && r->type == XCB_ATOM_INTEGER ) { + wmdesktop = *( (int *) xcb_get_property_value ( r ) ); } - if ( r&&r->type != XCB_ATOM_INTEGER) { + if ( r && 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); + free ( r ); continue; } - free(r); + free ( r ); if ( wmdesktop < 0xFFFFFFFF ) { snprintf ( desktop, 5, "%d", (int) wmdesktop ); @@ -539,9 +539,9 @@ static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **i } else{ xcb_ewmh_request_change_active_window ( &xcb_ewmh, xcb_screen_nbr, rmpd->ids->array[selected_line], - XCB_EWMH_CLIENT_SOURCE_TYPE_OTHER , - XCB_CURRENT_TIME, XCB_WINDOW_NONE); - xcb_flush(xcb_connection); + XCB_EWMH_CLIENT_SOURCE_TYPE_OTHER, + XCB_CURRENT_TIME, XCB_WINDOW_NONE ); + xcb_flush ( xcb_connection ); } } return retv; diff --git a/source/helper.c b/source/helper.c index dcce57ce..bcec3f36 100644 --- a/source/helper.c +++ b/source/helper.c @@ -47,9 +47,9 @@ #include "view.h" extern xcb_connection_t *xcb_connection; -extern xcb_screen_t *xcb_screen; -static int stored_argc = 0; -static char **stored_argv = NULL; +extern xcb_screen_t *xcb_screen; +static int stored_argc = 0; +static char **stored_argv = NULL; void cmd_set_arguments ( int argc, char **argv ) { @@ -511,7 +511,7 @@ void remove_pid_file ( int fd ) * * This functions exits the program with 1 when it finds an invalid configuration. */ -int config_sanity_check ( xcb_connection_t* xcb_connection) +int config_sanity_check ( xcb_connection_t* xcb_connection ) { // If alternative row is not set, copy the normal background color. // Do this at the beginning as we might use it in the error dialog. diff --git a/source/i3-support.c b/source/i3-support.c index 937bc74f..44c1b3b1 100644 --- a/source/i3-support.c +++ b/source/i3-support.c @@ -45,7 +45,7 @@ #ifdef HAVE_I3_IPC_H #include <i3/ipc.h> // Path to HAVE_I3_IPC_H socket. -char *i3_socket_path = NULL; +char *i3_socket_path = NULL; extern xcb_screen_t *xcb_screen; void i3_support_focus_window ( xcb_window_t id ) @@ -119,7 +119,7 @@ int i3_support_initialize ( xcb_connection_t *xcb_connection ) i3_support_free_internals (); // Get atom for I3_SOCKET_PATH - i3_socket_path = window_get_text_prop ( xcb_connection, xcb_screen->root, netatoms[I3_SOCKET_PATH]); + i3_socket_path = window_get_text_prop ( xcb_connection, xcb_screen->root, netatoms[I3_SOCKET_PATH] ); // If we find it, go into i3 mode. return ( i3_socket_path != NULL ) ? TRUE : FALSE; } diff --git a/source/rofi.c b/source/rofi.c index a26d2813..6d5e0508 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -64,30 +64,30 @@ #include "xkb-internal.h" // Pidfile. -char *pidfile = NULL; -const char *cache_dir = NULL; -SnDisplay *sndisplay = NULL; -SnLauncheeContext *sncontext = NULL; -xcb_connection_t *xcb_connection = NULL; +char *pidfile = NULL; +const char *cache_dir = NULL; +SnDisplay *sndisplay = NULL; +SnLauncheeContext *sncontext = NULL; +xcb_connection_t *xcb_connection = NULL; xcb_ewmh_connection_t xcb_ewmh; -xcb_screen_t *xcb_screen = NULL; -int xcb_screen_nbr = -1; -struct xkb_stuff xkb = { NULL }; -char *display_str = NULL; -char *config_path = NULL; +xcb_screen_t *xcb_screen = NULL; +int xcb_screen_nbr = -1; +struct xkb_stuff xkb = { NULL }; +char *display_str = NULL; +char *config_path = NULL; // Array of modi. -Mode **modi = NULL; -unsigned int num_modi = 0; +Mode **modi = NULL; +unsigned int num_modi = 0; // Current selected switcher. -unsigned int curr_switcher = 0; +unsigned int curr_switcher = 0; -GMainLoop *main_loop = NULL; -GWaterXcbSource *main_loop_source = NULL; -gboolean quiet = FALSE; +GMainLoop *main_loop = NULL; +GWaterXcbSource *main_loop_source = NULL; +gboolean quiet = FALSE; -static int dmenu_mode = FALSE; +static int dmenu_mode = FALSE; -int return_code = EXIT_SUCCESS; +int return_code = EXIT_SUCCESS; void process_result ( RofiViewState *state ); void process_result_error ( RofiViewState *state ); @@ -324,7 +324,7 @@ static void cleanup () sn_display_unref ( sndisplay ); sndisplay = NULL; } - xcb_disconnect( xcb_connection ); + xcb_disconnect ( xcb_connection ); xcb_connection = NULL; } @@ -473,7 +473,6 @@ static gboolean main_loop_x11_event_handler ( xcb_generic_event_t *ev, G_GNUC_UN return G_SOURCE_CONTINUE; } - static gboolean main_loop_signal_handler_int ( G_GNUC_UNUSED gpointer data ) { // Break out of loop. @@ -494,7 +493,7 @@ static void error_trap_pop ( G_GNUC_UNUSED SnDisplay *display, xcb_connection_t exit ( EXIT_FAILURE ); } - xcb_flush(xdisplay); + xcb_flush ( xdisplay ); --error_trap_depth; } @@ -506,7 +505,7 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data ) char *msg = NULL; // // Sanity check - if ( config_sanity_check ( xcb_connection) ) { + if ( config_sanity_check ( xcb_connection ) ) { return G_SOURCE_REMOVE; } TICK_N ( "Config sanity check" ); @@ -632,16 +631,15 @@ int main ( int argc, char *argv[] ) xcb_connection = xcb_connect ( display_str, &xcb_screen_nbr ); TICK_N ( "Open Display" ); - xcb_screen = xcb_aux_get_screen ( xcb_connection, xcb_screen_nbr ); + xcb_screen = xcb_aux_get_screen ( xcb_connection, xcb_screen_nbr ); - xcb_intern_atom_cookie_t *ac = xcb_ewmh_init_atoms(xcb_connection, &xcb_ewmh); - xcb_generic_error_t **errors = NULL; - xcb_ewmh_init_atoms_replies(&xcb_ewmh, ac, errors); - if (errors){ - fprintf(stderr, "Failed to create EWMH atoms\n"); + xcb_intern_atom_cookie_t *ac = xcb_ewmh_init_atoms ( xcb_connection, &xcb_ewmh ); + xcb_generic_error_t **errors = NULL; + xcb_ewmh_init_atoms_replies ( &xcb_ewmh, ac, errors ); + if ( errors ) { + fprintf ( stderr, "Failed to create EWMH atoms\n" ); } - if ( xkb_x11_setup_xkb_extension ( xcb_connection, XKB_X11_MIN_MAJOR_XKB_VERSION, XKB_X11_MIN_MINOR_XKB_VERSION, XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS, NULL, NULL, &xkb.first_event, NULL ) < 0 ) { fprintf ( stderr, "cannot setup XKB extension!\n" ); @@ -712,7 +710,7 @@ int main ( int argc, char *argv[] ) sndisplay = sn_xcb_display_new ( xcb_connection, error_trap_push, error_trap_pop ); if ( sndisplay != NULL ) { - sncontext = sn_launchee_context_new_from_environment ( sndisplay, xcb_screen_nbr); + sncontext = sn_launchee_context_new_from_environment ( sndisplay, xcb_screen_nbr ); } TICK_N ( "Startup Notification" ); diff --git a/source/view.c b/source/view.c index 3baeb40f..c049c888 100644 --- a/source/view.c +++ b/source/view.c @@ -62,18 +62,18 @@ #include "view-internal.h" // What todo with these. -extern xcb_connection_t *xcb_connection; -extern xcb_screen_t *xcb_screen; -extern SnLauncheeContext *sncontext; +extern xcb_connection_t *xcb_connection; +extern xcb_screen_t *xcb_screen; +extern SnLauncheeContext *sncontext; extern xcb_ewmh_connection_t xcb_ewmh; -GThreadPool *tpool = NULL; +GThreadPool *tpool = NULL; -RofiViewState *current_active_menu = NULL; -xcb_window_t main_window = XCB_WINDOW_NONE; -cairo_surface_t *surface = NULL; -cairo_surface_t *fake_bg = NULL; -cairo_t *draw = NULL; +RofiViewState *current_active_menu = NULL; +xcb_window_t main_window = XCB_WINDOW_NONE; +cairo_surface_t *surface = NULL; +cairo_surface_t *fake_bg = NULL; +cairo_t *draw = NULL; static char * get_matching_state ( void ) { @@ -388,32 +388,33 @@ void rofi_view_itterrate ( RofiViewState *state, xcb_generic_event_t *event, xkb } } } - else{ switch ( type ) - { - case XCB_EXPOSE: - state->update = TRUE; - break; - case XCB_CONFIGURE_NOTIFY: - { - xcb_configure_notify_event_t *xce = (xcb_configure_notify_event_t *) event; - if ( xce->window == main_window ) { - if ( state->x != xce->x || state->y != xce->y ) { - state->x = xce->x; - state->y = xce->y; - state->update = TRUE; - } - if ( state->w != xce->width || state->h != xce->height ) { - state->w = xce->width; - state->h = xce->height; - cairo_xcb_surface_set_size ( surface, state->w, state->h ); - rofi_view_resize ( state ); - } - } - break; - } - default: - state->x11_event_loop ( state, event, xkb ); - } + else{ + switch ( type ) + { + case XCB_EXPOSE: + state->update = TRUE; + break; + case XCB_CONFIGURE_NOTIFY: + { + xcb_configure_notify_event_t *xce = (xcb_configure_notify_event_t *) event; + if ( xce->window == main_window ) { + if ( state->x != xce->x || state->y != xce->y ) { + state->x = xce->x; + state->y = xce->y; + state->update = TRUE; + } + if ( state->w != xce->width || state->h != xce->height ) { + state->w = xce->width; + state->h = xce->height; + cairo_xcb_surface_set_size ( surface, state->w, state->h ); + rofi_view_resize ( state ); + } + } + break; + } + default: + state->x11_event_loop ( state, event, xkb ); + } } rofi_view_update ( state ); } @@ -492,7 +493,7 @@ static xcb_window_t __create_window ( xcb_connection_t *xcb_connection, xcb_scre { 0, 0, XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_KEY_PRESS | - XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_FOCUS_CHANGE | XCB_EVENT_MASK_BUTTON_1_MOTION,map }; + XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_FOCUS_CHANGE | XCB_EVENT_MASK_BUTTON_1_MOTION, map }; xcb_window_t box = xcb_generate_id ( xcb_connection ); xcb_create_window ( xcb_connection, @@ -540,8 +541,8 @@ static xcb_window_t __create_window ( xcb_connection_t *xcb_connection, xcb_scre // // make it an unmanaged window if ( ( ( menu_flags & MENU_NORMAL_WINDOW ) == 0 ) && !config.fullscreen ) { window_set_atom_prop ( xcb_connection, box, xcb_ewmh._NET_WM_STATE, &xcb_ewmh._NET_WM_STATE_ABOVE, 1 ); - uint32_t values[] = {1}; - xcb_change_window_attributes ( xcb_connection, box, XCB_CW_OVERRIDE_REDIRECT, values); + uint32_t values[] = { 1 }; + xcb_change_window_attributes ( xcb_connection, box, XCB_CW_OVERRIDE_REDIRECT, values ); } else{ window_set_atom_prop ( xcb_connection, box, xcb_ewmh._NET_WM_WINDOW_TYPE, &xcb_ewmh._NET_WM_WINDOW_TYPE_NORMAL, 1 ); @@ -555,8 +556,8 @@ static xcb_window_t __create_window ( xcb_connection_t *xcb_connection, xcb_scre } // Set the WM_NAME - 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"); + 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 ( xcb_connection, box, config.window_opacity ); return box; @@ -994,9 +995,10 @@ void rofi_view_update ( RofiViewState *state ) */ static void rofi_view_paste ( RofiViewState *state, xcb_selection_notify_event_t *xse ) { - if ( xse->property == XCB_ATOM_NONE ){ + if ( xse->property == XCB_ATOM_NONE ) { fprintf ( stderr, "Failed to convert selection\n" ); - } else if ( xse->property == xcb_ewmh.UTF8_STRING ) { + } + else if ( xse->property == xcb_ewmh.UTF8_STRING ) { gchar *text = window_get_text_prop ( xcb_connection, main_window, xcb_ewmh.UTF8_STRING ); if ( text != NULL && text[0] != '\0' ) { unsigned int dl = strlen ( text ); @@ -1013,7 +1015,8 @@ static void rofi_view_paste ( RofiViewState *state, xcb_selection_notify_event_t state->refilter = TRUE; } g_free ( text ); - } else { + } + else { fprintf ( stderr, "Failed\n" ); } } @@ -1343,12 +1346,12 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t // Handling of paste if ( abe_test_action ( PASTE_PRIMARY, modstate, key ) ) { xcb_convert_selection ( xcb_connection, main_window, XCB_ATOM_PRIMARY, - xcb_ewmh.UTF8_STRING,xcb_ewmh.UTF8_STRING, XCB_CURRENT_TIME ); + xcb_ewmh.UTF8_STRING, xcb_ewmh.UTF8_STRING, XCB_CURRENT_TIME ); xcb_flush ( xcb_connection ); } else if ( abe_test_action ( PASTE_SECONDARY, modstate, key ) ) { xcb_convert_selection ( xcb_connection, main_window, XCB_ATOM_SECONDARY, - xcb_ewmh.UTF8_STRING,xcb_ewmh.UTF8_STRING, XCB_CURRENT_TIME ); + xcb_ewmh.UTF8_STRING, xcb_ewmh.UTF8_STRING, XCB_CURRENT_TIME ); xcb_flush ( xcb_connection ); } if ( abe_test_action ( SCREENSHOT, modstate, key ) ) { diff --git a/source/x11-helper.c b/source/x11-helper.c index c48ca37d..9d67a454 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -62,29 +62,29 @@ enum NUM_X11MOD }; -xcb_depth_t *depth = NULL; -xcb_visualtype_t *visual = NULL; -xcb_colormap_t map = XCB_COLORMAP_NONE; -xcb_depth_t *root_depth = NULL; -xcb_visualtype_t *root_visual = NULL; -xcb_atom_t netatoms[NUM_NETATOMS]; -const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) }; -static unsigned int x11_mod_masks[NUM_X11MOD]; +xcb_depth_t *depth = NULL; +xcb_visualtype_t *visual = NULL; +xcb_colormap_t map = XCB_COLORMAP_NONE; +xcb_depth_t *root_depth = NULL; +xcb_visualtype_t *root_visual = NULL; +xcb_atom_t netatoms[NUM_NETATOMS]; +const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) }; +static unsigned int x11_mod_masks[NUM_X11MOD]; extern xcb_ewmh_connection_t xcb_ewmh; -extern xcb_connection_t *xcb_connection; +extern xcb_connection_t *xcb_connection; // retrieve a text property from a window // technically we could use window_get_prop(), but this is better for character set support char* window_get_text_prop ( xcb_connection_t *xcb_connection, xcb_window_t w, xcb_atom_t atom ) { - xcb_get_property_cookie_t c = xcb_get_property( xcb_connection, 0, w, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX); - xcb_get_property_reply_t *r = xcb_get_property_reply( xcb_connection, c, NULL); - if ( r ){ - char *str = g_malloc ( xcb_get_property_value_length(r)+1); - memcpy(str, xcb_get_property_value(r), xcb_get_property_value_length(r)); - str[xcb_get_property_value_length(r)] = '\0'; - free(r); + xcb_get_property_cookie_t c = xcb_get_property ( xcb_connection, 0, w, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX ); + xcb_get_property_reply_t *r = xcb_get_property_reply ( xcb_connection, c, NULL ); + if ( r ) { + char *str = g_malloc ( xcb_get_property_value_length ( r ) + 1 ); + memcpy ( str, xcb_get_property_value ( r ), xcb_get_property_value_length ( r ) ); + str[xcb_get_property_value_length ( r )] = '\0'; + free ( r ); return str; } return NULL; @@ -92,43 +92,43 @@ char* window_get_text_prop ( xcb_connection_t *xcb_connection, xcb_window_t w, x void window_set_atom_prop ( xcb_connection_t *xcb_connection, xcb_window_t 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); + xcb_change_property ( xcb_connection, XCB_PROP_MODE_REPLACE, w, prop, XCB_ATOM_ATOM, 32, count, atoms ); } extern xcb_screen_t *xcb_screen; -extern int xcb_screen_nbr; +extern int xcb_screen_nbr; int monitor_get_smallest_size ( xcb_connection_t *xcb_connection ) { - xcb_generic_error_t *error; - int size = MIN (xcb_screen->width_in_pixels, xcb_screen->height_in_pixels); - xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active(xcb_connection); - xcb_xinerama_is_active_reply_t *is_active = xcb_xinerama_is_active_reply(xcb_connection, is_active_req, &error); - if (error) { - fprintf(stderr, "Couldn't query Xinerama\n"); + xcb_generic_error_t *error; + int size = MIN ( xcb_screen->width_in_pixels, xcb_screen->height_in_pixels ); + xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active ( xcb_connection ); + xcb_xinerama_is_active_reply_t *is_active = xcb_xinerama_is_active_reply ( xcb_connection, is_active_req, &error ); + if ( error ) { + fprintf ( stderr, "Couldn't query Xinerama\n" ); return size; } - if (!is_active->state) { + if ( !is_active->state ) { free ( is_active ); return size; } free ( is_active ); xcb_xinerama_query_screens_cookie_t cookie_screen; - cookie_screen = xcb_xinerama_query_screens(xcb_connection); - xcb_xinerama_query_screens_reply_t *query_screens; - query_screens = xcb_xinerama_query_screens_reply(xcb_connection, cookie_screen, &error); - if (error) { - fprintf(stderr, "Error getting screen info\n"); + cookie_screen = xcb_xinerama_query_screens ( xcb_connection ); + xcb_xinerama_query_screens_reply_t *query_screens; + query_screens = xcb_xinerama_query_screens_reply ( xcb_connection, cookie_screen, &error ); + if ( error ) { + fprintf ( stderr, "Error getting screen info\n" ); return size; } - xcb_xinerama_screen_info_t *screens = xcb_xinerama_query_screens_screen_info(query_screens); - int len = xcb_xinerama_query_screens_screen_info_length(query_screens); - for (int i = 0; i < len; i++) { + xcb_xinerama_screen_info_t *screens = xcb_xinerama_query_screens_screen_info ( query_screens ); + int len = xcb_xinerama_query_screens_screen_info_length ( query_screens ); + for ( int i = 0; i < len; i++ ) { xcb_xinerama_screen_info_t *info = &screens[i]; - size = MIN ( info->width, size ); - size = MIN ( info->height, size ); + size = MIN ( info->width, size ); + size = MIN ( info->height, size ); } - free(query_screens); + free ( query_screens ); return size; } @@ -137,40 +137,40 @@ int monitor_get_dimension ( xcb_connection_t *xcb_connection, xcb_screen_t *scre xcb_generic_error_t *error = NULL; memset ( mon, 0, sizeof ( workarea ) ); mon->w = screen->width_in_pixels; - mon->h = screen->height_in_pixels; + mon->h = screen->height_in_pixels; - xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active(xcb_connection); - xcb_xinerama_is_active_reply_t *is_active = xcb_xinerama_is_active_reply(xcb_connection, is_active_req, &error); - if (error) { - fprintf |