1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Fix #348, give a warning when font failed to parse

This commit is contained in:
Dave Davenport 2016-03-01 19:48:18 +01:00
parent 8c950a984c
commit f05f0de583
9 changed files with 64 additions and 46 deletions

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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;
}

View file

@ -40,6 +40,9 @@
#include <pwd.h>
#include <ctype.h>
#include <xcb/xcb.h>
#include <pango/pango.h>
#include <pango/pango-fontmap.h>
#include <pango/pangocairo.h>
#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: <b>%s</b> at size <b>%d</b>\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 );

View file

@ -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;
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;
}

View file

@ -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 );

View file

@ -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;

View file

@ -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;
}
}