From ead84b9dca3e272d0b97c7a38b953648f5941c0d Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Mon, 1 Oct 2012 17:09:14 +0200 Subject: [PATCH] wlt: toggle fullscreen on F11 This adds a --grab-fullscreen parameter which configures the key that toggles fullscreen. This is handled in the theme widget as we consider it the main window-handler. Signed-off-by: David Herrmann --- src/wlt_main.c | 9 +++++++++ src/wlt_main.h | 2 ++ src/wlt_theme.c | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/wlt_main.c b/src/wlt_main.c index e6a0895..a73e647 100644 --- a/src/wlt_main.c +++ b/src/wlt_main.c @@ -234,6 +234,9 @@ static void print_help() "\t Shortcut to scroll page up\n" "\t --grab-page-down [Next]\n" "\t Shortcut to scroll page down\n" + "\t --grab-fullscreen [F11]\n" + "\t Shortcut to toggle fullscreen mode\n" + "\n" "Font Options:\n" "\t --font-engine [pango]\n" "\t Font engine\n" @@ -321,6 +324,11 @@ static struct conf_grab def_grab_page_down = { .keysym = XKB_KEY_Next, }; +static struct conf_grab def_grab_fullscreen = { + .mods = 0, + .keysym = XKB_KEY_F11, +}; + struct conf_option options[] = { CONF_OPTION_BOOL('h', "help", aftercheck_help, &wlt_conf.help, false), CONF_OPTION_BOOL('v', "verbose", NULL, &wlt_conf.verbose, false), @@ -336,6 +344,7 @@ struct conf_option options[] = { CONF_OPTION_GRAB(0, "grab-scroll-down", NULL, &wlt_conf.grab_scroll_down, &def_grab_scroll_down), CONF_OPTION_GRAB(0, "grab-page-up", NULL, &wlt_conf.grab_page_up, &def_grab_page_up), CONF_OPTION_GRAB(0, "grab-page-down", NULL, &wlt_conf.grab_page_down, &def_grab_page_down), + CONF_OPTION_GRAB(0, "grab-fullscreen", NULL, &wlt_conf.grab_fullscreen, &def_grab_fullscreen), CONF_OPTION_STRING(0, "font-engine", NULL, &wlt_conf.font_engine, "pango"), CONF_OPTION_UINT(0, "font-size", NULL, &wlt_conf.font_size, 12), diff --git a/src/wlt_main.h b/src/wlt_main.h index 99d90ed..e18fff5 100644 --- a/src/wlt_main.h +++ b/src/wlt_main.h @@ -65,6 +65,8 @@ struct wlt_conf_t { struct conf_grab *grab_page_up; /* page-down grab */ struct conf_grab *grab_page_down; + /* fullscreen grab */ + struct conf_grab *grab_fullscreen; /* font engine */ char *font_engine; diff --git a/src/wlt_theme.c b/src/wlt_theme.c index 025208d..5da7716 100644 --- a/src/wlt_theme.c +++ b/src/wlt_theme.c @@ -33,6 +33,8 @@ #include #include #include "log.h" +#include "shl_misc.h" +#include "wlt_main.h" #include "wlt_theme.h" #include "wlt_toolkit.h" @@ -519,6 +521,24 @@ static void widget_pointer_button(struct wlt_widget *widget, } } +static bool widget_key(struct wlt_widget *widget, unsigned int mask, + uint32_t sym, uint32_t state, bool handled, void *data) +{ + struct wlt_theme *theme = data; + + if (handled || state != WL_KEYBOARD_KEY_STATE_PRESSED) + return false; + + if (SHL_HAS_BITS(mask, wlt_conf.grab_fullscreen->mods) && + sym == wlt_conf.grab_fullscreen->keysym) { + wlt_window_toggle_fullscreen(theme->wnd); + return true; + } + + return false; +} + + static void widget_destroy(struct wlt_widget *widget, void *data) { struct wlt_theme *theme = data; @@ -565,6 +585,7 @@ int wlt_theme_new(struct wlt_theme **out, struct wlt_window *wnd) wlt_widget_set_pointer_cb(theme->widget, widget_pointer_enter, widget_pointer_leave, widget_pointer_motion, widget_pointer_button); + wlt_widget_set_keyboard_cb(theme->widget, widget_key); *out = theme; return 0; -- 2.7.4