From f05f0de58346557df24dd7c3f5d04e9df913525f Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 1 Mar 2016 19:48:18 +0100 Subject: [PATCH] Fix #348, give a warning when font failed to parse --- include/textbox.h | 18 +++++++++--------- include/xcb.h | 2 +- include/xkb.h | 2 +- source/dialogs/window.c | 2 +- source/helper.c | 17 +++++++++++++++++ source/i3-support.c | 4 ++-- source/rofi.c | 10 +++++----- source/view.c | 34 ++++++++++++++++++---------------- source/x11-helper.c | 21 ++++++++++----------- 9 files changed, 64 insertions(+), 46 deletions(-) diff --git a/include/textbox.h b/include/textbox.h index e1d608e1..3d3b8d09 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -38,15 +38,15 @@ typedef struct typedef enum { - TB_AUTOHEIGHT = 1 << 0, - TB_AUTOWIDTH = 1 << 1, - TB_LEFT = 1 << 16, - TB_RIGHT = 1 << 17, - TB_CENTER = 1 << 18, - TB_EDITABLE = 1 << 19, - TB_MARKUP = 1 << 20, - TB_WRAP = 1 << 21, - TB_PASSWORD = 1 << 22, + TB_AUTOHEIGHT = 1 << 0, + TB_AUTOWIDTH = 1 << 1, + TB_LEFT = 1 << 16, + TB_RIGHT = 1 << 17, + TB_CENTER = 1 << 18, + TB_EDITABLE = 1 << 19, + TB_MARKUP = 1 << 20, + TB_WRAP = 1 << 21, + TB_PASSWORD = 1 << 22, } TextboxFlags; typedef enum diff --git a/include/xcb.h b/include/xcb.h index befc95f3..47e235ab 100644 --- a/include/xcb.h +++ b/include/xcb.h @@ -1,7 +1,7 @@ #ifndef ROFI_XCB_H #define ROFI_XCB_H -typedef struct _xcb_stuff xcb_stuff; +typedef struct _xcb_stuff xcb_stuff; extern xcb_stuff *xcb; diff --git a/include/xkb.h b/include/xkb.h index cd415c60..5fbd68ad 100644 --- a/include/xkb.h +++ b/include/xkb.h @@ -1,5 +1,5 @@ #ifndef ROFI_XKB_H #define ROFI_XKB_H -typedef struct xkb_stuff xkb_stuff; +typedef struct xkb_stuff xkb_stuff; #endif diff --git a/source/dialogs/window.c b/source/dialogs/window.c index a0dc6249..fcbcc8c6 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -372,7 +372,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) x11_cache_create (); // Check for i3 pd->config_i3_mode = i3_support_initialize ( xcb ); - xcb_get_property_cookie_t c = xcb_ewmh_get_active_window ( &(xcb->ewmh), xcb->screen_nbr ); + 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; } diff --git a/source/helper.c b/source/helper.c index d32e6b9d..e7425fa3 100644 --- a/source/helper.c +++ b/source/helper.c @@ -40,6 +40,9 @@ #include #include #include +#include +#include +#include #include "helper.h" #include "settings.h" #include "x11-helper.h" @@ -576,6 +579,20 @@ int config_sanity_check ( void ) } } + PangoFontDescription * pfd = NULL; + if ( config.menu_font ) { + PangoFontDescription *pfd = pango_font_description_from_string ( config.menu_font ); + const char *fam = pango_font_description_get_family ( pfd ); + int size = pango_font_description_get_size ( pfd ); + if ( fam == NULL || size == 0 ) { + g_string_append_printf ( msg, "Pango failed to parse font: '%s'\n", config.menu_font ); + g_string_append_printf ( msg, "Got font family: %s at size %d\n", fam ? fam : "{unknown}", size ); + config.menu_font = NULL; + found_error = TRUE; + } + pango_font_description_free ( pfd ); + } + if ( found_error ) { g_string_append ( msg, "Please update your configuration." ); show_error_message ( msg->str, TRUE ); diff --git a/source/i3-support.c b/source/i3-support.c index 7335930b..c92fd575 100644 --- a/source/i3-support.c +++ b/source/i3-support.c @@ -45,7 +45,7 @@ #ifdef HAVE_I3_IPC_H #include // Path to HAVE_I3_IPC_H socket. -char *i3_socket_path = NULL; +char *i3_socket_path = NULL; void i3_support_focus_window ( xcb_window_t id ) { i3_ipc_header_t head; @@ -117,7 +117,7 @@ int i3_support_initialize ( xcb_stuff *xcb ) i3_support_free_internals (); // Get atom for I3_SOCKET_PATH - i3_socket_path = window_get_text_prop ( xcb_stuff_get_root_window(xcb), netatoms[I3_SOCKET_PATH] ); + i3_socket_path = window_get_text_prop ( xcb_stuff_get_root_window ( xcb ), 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 b641b292..fbb0d53e 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -65,7 +65,7 @@ // Pidfile. char *pidfile = NULL; const char *cache_dir = NULL; -struct xkb_stuff xkb = { NULL }; +struct xkb_stuff xkb = { NULL }; char *config_path = NULL; // Array of modi. Mode **modi = NULL; @@ -670,10 +670,10 @@ int main ( int argc, char *argv[] ) .stateDetails = required_state_details, }; xcb_xkb_select_events ( xcb->connection, xkb.device_id, required_events, /* affectWhich */ - 0, /* clear */ - 0, /* selectAll */ - required_map_parts, /* affectMap */ - required_map_parts, /* map */ + 0, /* clear */ + 0, /* selectAll */ + required_map_parts, /* affectMap */ + required_map_parts, /* map */ &details ); xkb.keymap = xkb_x11_keymap_new_from_device ( xkb.context, xcb->connection, xkb.device_id, XKB_KEYMAP_COMPILE_NO_FLAGS ); diff --git a/source/view.c b/source/view.c index 85ff6f18..09857af0 100644 --- a/source/view.c +++ b/source/view.c @@ -64,13 +64,13 @@ #include "xcb.h" -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 ) { @@ -496,13 +496,13 @@ static xcb_window_t __create_window ( MenuFlags menu_flags ) { 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, depth->depth, box, - xcb_stuff_get_root_window(xcb), + xcb_stuff_get_root_window ( xcb ), 0, 0, 200, @@ -532,9 +532,11 @@ static xcb_window_t __create_window ( MenuFlags menu_flags ) pango_cairo_font_map_set_resolution ( (PangoCairoFontMap *) font_map, (double) config.dpi ); } // Setup font. - PangoFontDescription *pfd = pango_font_description_from_string ( config.menu_font ); - pango_context_set_font_description ( p, pfd ); - pango_font_description_free ( pfd ); + if ( config.menu_font ) { + PangoFontDescription *pfd = pango_font_description_from_string ( config.menu_font ); + pango_context_set_font_description ( p, pfd ); + pango_font_description_free ( pfd ); + } // Tell textbox to use this context. textbox_set_pango_context ( p ); // cleanup @@ -543,12 +545,12 @@ static xcb_window_t __create_window ( MenuFlags menu_flags ) // // make it an unmanaged window if ( ( ( menu_flags & MENU_NORMAL_WINDOW ) == 0 ) && !config.fullscreen ) { - window_set_atom_prop ( box, xcb->ewmh._NET_WM_STATE, &(xcb->ewmh._NET_WM_STATE_ABOVE), 1 ); + window_set_atom_prop ( 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 ); } else{ - window_set_atom_prop ( box, xcb->ewmh._NET_WM_WINDOW_TYPE, &(xcb->ewmh._NET_WM_WINDOW_TYPE_NORMAL), 1 ); + window_set_atom_prop ( box, xcb->ewmh._NET_WM_WINDOW_TYPE, &( xcb->ewmh._NET_WM_WINDOW_TYPE_NORMAL ), 1 ); } if ( config.fullscreen ) { xcb_atom_t atoms[] = { @@ -1268,7 +1270,7 @@ void rofi_view_setup_fake_transparency ( RofiViewState *state ) { if ( fake_bg == NULL ) { cairo_surface_t *s = cairo_xcb_surface_create ( xcb->connection, - xcb_stuff_get_root_window(xcb), + xcb_stuff_get_root_window ( xcb ), root_visual, xcb->screen->width_in_pixels, xcb->screen->height_in_pixels ); @@ -1552,7 +1554,7 @@ RofiViewState *rofi_view_create ( Mode *sw, // We grab this using the rootwindow (as dmenu does it). // this seems to result in the smallest delay for most people. if ( ( menu_flags & MENU_NORMAL_WINDOW ) == 0 ) { - int has_keyboard = take_keyboard ( xcb_stuff_get_root_window(xcb) ); + int has_keyboard = take_keyboard ( xcb_stuff_get_root_window ( xcb ) ); if ( !has_keyboard ) { fprintf ( stderr, "Failed to grab keyboard, even after %d uS.", 500 * 1000 ); @@ -1724,7 +1726,7 @@ void rofi_view_error_dialog ( const char *msg, int markup ) // Try to grab the keyboard as early as possible. // We grab this using the rootwindow (as dmenu does it). // this seems to result in the smallest delay for most people. - int has_keyboard = take_keyboard ( xcb_stuff_get_root_window(xcb)); + int has_keyboard = take_keyboard ( xcb_stuff_get_root_window ( xcb ) ); if ( !has_keyboard ) { fprintf ( stderr, "Failed to grab keyboard, even after %d uS.", 500 * 1000 ); return; diff --git a/source/x11-helper.c b/source/x11-helper.c index c2d7b9e5..58ef8444 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -51,7 +51,6 @@ #include "x11-helper.h" #include "xkb-internal.h" - struct _xcb_stuff xcb_int = { .connection = NULL, .screen = NULL, @@ -59,7 +58,7 @@ struct _xcb_stuff xcb_int = { .sndisplay = NULL, .sncontext = NULL, }; -xcb_stuff *xcb = &xcb_int; +xcb_stuff *xcb = &xcb_int; enum { @@ -73,14 +72,14 @@ 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]; // retrieve a text property from a window // technically we could use window_get_prop(), but this is better for character set support @@ -696,7 +695,7 @@ void xcb_stuff_wipe ( xcb_stuff *xcb ) } xcb_disconnect ( xcb->connection ); xcb->connection = NULL; - xcb->screen = NULL; + xcb->screen = NULL; xcb->screen_nbr = 0; } }