summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--include/display.h66
-rw-r--r--include/xcb-internal.h1
-rw-r--r--include/xcb.h60
-rw-r--r--meson.build1
-rw-r--r--source/rofi.c23
-rw-r--r--source/view.c3
-rw-r--r--source/xcb.c76
8 files changed, 122 insertions, 109 deletions
diff --git a/Makefile.am b/Makefile.am
index cf770f11..980c0d3e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -73,6 +73,7 @@ SOURCES=\
source/dialogs/window.c\
source/dialogs/script.c\
source/dialogs/help-keys.c\
+ include/display.h\
include/xcb.h\
include/xcb-internal.h\
include/rofi.h\
diff --git a/include/display.h b/include/display.h
new file mode 100644
index 00000000..b0feb8c7
--- /dev/null
+++ b/include/display.h
@@ -0,0 +1,66 @@
+/*
+ * rofi
+ *
+ * MIT/X11 License
+ * Copyright © 2013-2017 Qball Cow <qball@gmpclient.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef ROFI_DISPLAY_H
+#define ROFI_DISPLAY_H
+
+#include <glib.h>
+#include "nkutils-bindings.h"
+
+/**
+ * @param main_loop The GMainLoop
+ * @param bindings The bindings object
+ *
+ * Setup the display backend
+ *
+ * @returns Whether the setup succeeded or not
+ */
+gboolean display_setup(GMainLoop *main_loop, NkBindings *bindings);
+
+/**
+ * Do some late setup of the display backend
+ *
+ * @returns Whether the setup succeeded or not
+ */
+gboolean display_late_setup(void);
+
+/**
+ * Do some early cleanup, like unmapping the surface
+ */
+void display_early_cleanup(void);
+
+/**
+ * Cleanup any remaining display related stuff
+ */
+void display_cleanup(void);
+
+/**
+ * Dumps the display layout for -help output
+ */
+void display_dump_monitor_layout ( void );
+
+#endif
diff --git a/include/xcb-internal.h b/include/xcb-internal.h
index 4189dc63..d01f110a 100644
--- a/include/xcb-internal.h
+++ b/include/xcb-internal.h
@@ -58,7 +58,6 @@ struct _xcb_stuff
/** Keyboard device id */
int32_t device_id;
} xkb;
- NkBindings *bindings;
NkBindingsSeat *bindings_seat;
gboolean mouse_seen;
};
diff --git a/include/xcb.h b/include/xcb.h
index bca40cd8..1223b440 100644
--- a/include/xcb.h
+++ b/include/xcb.h
@@ -49,12 +49,6 @@ extern xcb_stuff *xcb;
* @returns the root window.
*/
xcb_window_t xcb_stuff_get_root_window ( void );
-/**
- * @param xcb The xcb data structure.
- *
- * Disconnect and free all xcb connections and references.
- */
-void xcb_stuff_wipe ( void );
/**
* @param w The xcb_window_t to read property from.
@@ -102,29 +96,6 @@ extern const char *netatom_names[];
extern xcb_atom_t netatoms[NUM_NETATOMS];
/**
- * Enumerator describing the different modifier keys.
- */
-enum
-{
- /** Shift key */
- X11MOD_SHIFT,
- /** Control Key */
- X11MOD_CONTROL,
- /** Alt key */
- X11MOD_ALT,
- /** Meta key */
- X11MOD_META,
- /** Super (window) key */
- X11MOD_SUPER,
- /** Hyper key */
- X11MOD_HYPER,
- /** Any modifier */
- X11MOD_ANY,
- /** Number of modifier keys */
- NUM_X11MOD
-};
-
-/**
* Structure describing a workarea/monitor.
*/
typedef struct _workarea
@@ -158,18 +129,6 @@ typedef struct _workarea
int monitor_active ( workarea *mon );
/**
- * @param main_loop The GMainLoop
- *
- * Setup several items required.
- * * Error handling,
- * * Numlock detection
- * * Cache
- *
- * @returns Whether the setup succeeded or not
- */
-gboolean x11_setup ( GMainLoop *main_loop );
-
-/**
* Depth of visual
*/
extern xcb_depth_t *depth;
@@ -182,10 +141,6 @@ extern xcb_visualtype_t *visual;
*/
extern xcb_colormap_t map;
-gboolean x11_late_setup ( void );
-
-void x11_early_cleanup ( void );
-
/**
* Gets a surface containing the background image of the desktop.
*
@@ -202,17 +157,6 @@ cairo_surface_t * x11_helper_get_bg_surface ( void );
cairo_surface_t *x11_helper_get_screenshot_surface ( void );
/**
- * Creates an internal represenation of the available monitors.
- * Used for positioning rofi.
- */
-void x11_build_monitor_layout ( void );
-
-/**
- * Dump the monitor layout to stdout.
- */
-void x11_dump_monitor_layout ( void );
-
-/**
* @param window The X11 window to modify
*
* Set the right hints to disable the window decoration.
@@ -241,8 +185,4 @@ typedef enum
*/
extern WindowManager current_window_manager;
-/**
- * discover the window manager.
- */
-void x11_helper_discover_window_manager ( void );
#endif
diff --git a/meson.build b/meson.build
index d852d148..32847530 100644
--- a/meson.build
+++ b/meson.build
@@ -164,6 +164,7 @@ rofi_sources = files(
'source/dialogs/window.c',
'source/dialogs/script.c',
'source/dialogs/help-keys.c',
+ 'include/display.h',
'include/xcb.h',
'include/xcb-internal.h',
'include/rofi.h',
diff --git a/source/rofi.c b/source/rofi.c
index 9c52437c..daf8123c 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -45,7 +45,7 @@
#include <libgwater-xcb.h>
-#include "xcb-internal.h"
+#include "display.h"
#include "settings.h"
#include "mode.h"
@@ -95,6 +95,8 @@ unsigned int num_modi = 0;
/** Current selected mode */
unsigned int curr_switcher = 0;
+NkBindings *bindings = NULL;
+
/** Glib main loop. */
GMainLoop *main_loop = NULL;
@@ -146,7 +148,7 @@ static void teardown ( int pfd )
// Cleanup font setup.
textbox_cleanup ( );
- x11_early_cleanup ();
+ display_early_cleanup ();
// Cleanup view
rofi_view_cleanup ();
@@ -277,7 +279,7 @@ static void help ( G_GNUC_UNUSED int argc, char **argv )
printf ( "Global options:\n" );
print_options ();
printf ( "\n" );
- x11_dump_monitor_layout ();
+ display_dump_monitor_layout ();
printf ( "\n" );
printf ( "Detected modi:\n" );
print_list_of_modi ( is_term );
@@ -399,7 +401,9 @@ static void cleanup ()
main_loop = NULL;
}
// Cleanup
- xcb_stuff_wipe ();
+ display_cleanup ();
+
+ nk_bindings_free ( bindings );
// Cleaning up memory allocated by the Xresources file.
config_xresource_free ();
@@ -785,7 +789,9 @@ int main ( int argc, char *argv[] )
TICK_N ( "Setup mainloop" );
- if ( !x11_setup ( main_loop ) ) {
+ bindings = nk_bindings_new ();
+
+ if ( !display_setup ( main_loop, bindings ) ) {
g_warning ( "Connection has error" );
cleanup ();
return EXIT_FAILURE;
@@ -821,6 +827,11 @@ int main ( int argc, char *argv[] )
config_parse_cmd_options ( );
TICK_N ( "Load cmd config " );
+ if ( !parse_keys_abe ( bindings ) ) {
+ cleanup ();
+ return EXIT_FAILURE;
+ }
+
if ( !dmenu_mode ) {
// setup_modi
if ( setup_modi () ) {
@@ -890,7 +901,7 @@ int main ( int argc, char *argv[] )
}
textbox_setup ();
- if ( !x11_late_setup () ) {
+ if ( !display_late_setup () ) {
g_warning ( "Failed to properly finish display setup" );
cleanup ();
return EXIT_FAILURE;
diff --git a/source/view.c b/source/view.c
index 824d2300..3ea8962d 100644
--- a/source/view.c
+++ b/source/view.c
@@ -54,6 +54,7 @@
#include "rofi.h"
#include "mode.h"
+#include "display.h"
#include "xcb-internal.h"
#include "helper.h"
#include "helper-theme.h"
@@ -1722,7 +1723,7 @@ void rofi_view_hide ( void )
{
if ( CacheState.main_window != XCB_WINDOW_NONE ) {
xcb_unmap_window ( xcb->connection, CacheState.main_window );
- x11_early_cleanup ();
+ display_early_cleanup ();
}
}
diff --git a/source/xcb.c b/source/xcb.c
index 60e8bd6e..13dbdd6a 100644
--- a/source/xcb.c
+++ b/source/xcb.c
@@ -49,6 +49,7 @@
#include <xcb/xkb.h>
#include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-x11.h>
+#include "display.h"
#include "xcb-internal.h"
#include "xcb.h"
#include "settings.h"
@@ -277,7 +278,7 @@ static void x11_build_monitor_layout_xinerama ()
free ( screens_reply );
}
-void x11_build_monitor_layout ()
+static void x11_build_monitor_layout ()
{
if ( xcb->monitors ) {
return;
@@ -331,7 +332,7 @@ void x11_build_monitor_layout ()
free ( res_reply );
}
-void x11_dump_monitor_layout ( void )
+void display_dump_monitor_layout ( void )
{
int is_term = isatty ( fileno ( stdout ) );
printf ( "Monitor layout:\n" );
@@ -798,7 +799,34 @@ static void x11_create_frequently_used_atoms ( void )
}
}
-gboolean x11_setup ( GMainLoop *main_loop )
+static void x11_helper_discover_window_manager ( void )
+{
+ xcb_window_t wm_win = 0;
+ xcb_get_property_cookie_t cc = xcb_ewmh_get_supporting_wm_check_unchecked ( &xcb->ewmh,
+ xcb_stuff_get_root_window () );
+
+ if ( xcb_ewmh_get_supporting_wm_check_reply ( &xcb->ewmh, cc, &wm_win, NULL ) ) {
+ xcb_ewmh_get_utf8_strings_reply_t wtitle;
+ xcb_get_property_cookie_t cookie = xcb_ewmh_get_wm_name_unchecked ( &( xcb->ewmh ), wm_win );
+ if ( xcb_ewmh_get_wm_name_reply ( &( xcb->ewmh ), cookie, &wtitle, (void *) 0 ) ) {
+ if ( wtitle.strings_len > 0 ) {
+ g_debug ( "Found window manager: %s", wtitle.strings );
+ if ( g_strcmp0 ( wtitle.strings, "i3" ) == 0 ) {
+ current_window_manager = WM_I3;
+ }
+ else if ( g_strcmp0 ( wtitle.strings, "awesome" ) == 0 ) {
+ current_window_manager = WM_AWESOME;
+ }
+ else if ( g_strcmp0 ( wtitle.strings, "Openbox" ) == 0 ) {
+ current_window_manager = WM_OPENBOX;
+ }
+ }
+ xcb_ewmh_get_utf8_strings_reply_wipe ( &wtitle );
+ }
+ }
+}
+
+gboolean display_setup ( GMainLoop *main_loop, NkBindings *bindings )
{
// Get DISPLAY, first env, then argument.
// We never modify display_str content.
@@ -879,8 +907,7 @@ gboolean x11_setup ( GMainLoop *main_loop )
required_map_parts, /* map */
&details );
- xcb->bindings = nk_bindings_new ();
- xcb->bindings_seat = nk_bindings_seat_new ( xcb->bindings, XKB_CONTEXT_NO_FLAGS );
+ xcb->bindings_seat = nk_bindings_seat_new ( bindings, XKB_CONTEXT_NO_FLAGS );
struct xkb_keymap *keymap = xkb_x11_keymap_new_from_device ( nk_bindings_seat_get_context ( xcb->bindings_seat ), xcb->connection, xcb->xkb.device_id, XKB_KEYMAP_COMPILE_NO_FLAGS );
if ( keymap == NULL ) {
g_warning ( "Failed to get Keymap for current keyboard device." );
@@ -894,11 +921,6 @@ gboolean x11_setup ( GMainLoop *main_loop )
nk_bindings_seat_update_keymap ( xcb->bindings_seat, keymap, state );
- if ( !parse_keys_abe ( xcb->bindings ) ) {
- // Error dialog
- return FALSE;
- }
-
// determine numlock mask so we can bind on keys with and without it
x11_create_frequently_used_atoms ( );
@@ -997,7 +1019,7 @@ static gboolean lazy_grab_keyboard ( G_GNUC_UNUSED gpointer data )
return G_SOURCE_CONTINUE;
}
-gboolean x11_late_setup ( void )
+gboolean display_late_setup ( void )
{
x11_create_visual_and_colormap ();
@@ -1035,14 +1057,14 @@ xcb_window_t xcb_stuff_get_root_window ( void )
return xcb->screen->root;
}
-void x11_early_cleanup ( void )
+void display_early_cleanup ( void )
{
release_keyboard ( );
release_pointer ( );
xcb_flush ( xcb->connection );
}
-void xcb_stuff_wipe ( void )
+void display_cleanup ( void )
{
if ( xcb->connection == NULL ) {
return;
@@ -1051,7 +1073,6 @@ void xcb_stuff_wipe ( void )
g_debug ( "Cleaning up XCB and XKB" );
nk_bindings_seat_free ( xcb->bindings_seat );
- nk_bindings_free ( xcb->bindings );
if ( xcb->sncontext != NULL ) {
sn_launchee_context_unref ( xcb->sncontext );
xcb->sncontext = NULL;
@@ -1095,30 +1116,3 @@ void x11_disable_decoration ( xcb_window_t window )
xcb_atom_t ha = netatoms[_MOTIF_WM_HINTS];
xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, window, ha, ha, 32, 5, &hints );
}
-
-void x11_helper_discover_window_manager ( void )
-{
- xcb_window_t wm_win = 0;
- xcb_get_property_cookie_t cc = xcb_ewmh_get_supporting_wm_check_unchecked ( &xcb->ewmh,
- xcb_stuff_get_root_window () );
-
- if ( xcb_ewmh_get_supporting_wm_check_reply ( &xcb->ewmh, cc, &wm_win, NULL ) ) {
- xcb_ewmh_get_utf8_strings_reply_t wtitle;
- xcb_get_property_cookie_t cookie = xcb_ewmh_get_wm_name_unchecked ( &( xcb->ewmh ), wm_win );
- if ( xcb_ewmh_get_wm_name_reply ( &( xcb->ewmh ), cookie, &wtitle, (void *) 0 ) ) {
- if ( wtitle.strings_len > 0 ) {
- g_debug ( "Found window manager: %s", wtitle.strings );
- if ( g_strcmp0 ( wtitle.strings, "i3" ) == 0 ) {
- current_window_manager = WM_I3;
- }
- else if ( g_strcmp0 ( wtitle.strings, "awesome" ) == 0 ) {
- current_window_manager = WM_AWESOME;
- }
- else if ( g_strcmp0 ( wtitle.strings, "Openbox" ) == 0 ) {
- current_window_manager = WM_OPENBOX;
- }
- }
- xcb_ewmh_get_utf8_strings_reply_wipe ( &wtitle );
- }
- }
-}