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

display: Introduce display.h

The API is meant to be neutral to fit any display backend.

Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
Quentin Glidic 2017-06-01 14:55:17 +02:00
parent 55485418a4
commit 48a80e3f82
No known key found for this signature in database
GPG key ID: AC203F96E2C34BB7
8 changed files with 94 additions and 55 deletions

View file

@ -73,6 +73,7 @@ SOURCES=\
source/dialogs/window.c\ source/dialogs/window.c\
source/dialogs/script.c\ source/dialogs/script.c\
source/dialogs/help-keys.c\ source/dialogs/help-keys.c\
include/display.h\
include/xcb.h\ include/xcb.h\
include/xcb-internal.h\ include/xcb-internal.h\
include/rofi.h\ include/rofi.h\

66
include/display.h Normal file
View file

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

View file

@ -58,7 +58,6 @@ struct _xcb_stuff
/** Keyboard device id */ /** Keyboard device id */
int32_t device_id; int32_t device_id;
} xkb; } xkb;
NkBindings *bindings;
NkBindingsSeat *bindings_seat; NkBindingsSeat *bindings_seat;
gboolean mouse_seen; gboolean mouse_seen;
}; };

View file

@ -49,12 +49,6 @@ extern xcb_stuff *xcb;
* @returns the root window. * @returns the root window.
*/ */
xcb_window_t xcb_stuff_get_root_window ( void ); 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. * @param w The xcb_window_t to read property from.
@ -134,18 +128,6 @@ typedef struct _workarea
*/ */
int monitor_active ( workarea *mon ); 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 * Depth of visual
*/ */
@ -159,10 +141,6 @@ extern xcb_visualtype_t *visual;
*/ */
extern xcb_colormap_t map; 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. * Gets a surface containing the background image of the desktop.
* *
@ -178,17 +156,6 @@ cairo_surface_t * x11_helper_get_bg_surface ( void );
*/ */
cairo_surface_t *x11_helper_get_screenshot_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 * @param window The X11 window to modify
* *

View file

@ -164,6 +164,7 @@ rofi_sources = files(
'source/dialogs/window.c', 'source/dialogs/window.c',
'source/dialogs/script.c', 'source/dialogs/script.c',
'source/dialogs/help-keys.c', 'source/dialogs/help-keys.c',
'include/display.h',
'include/xcb.h', 'include/xcb.h',
'include/xcb-internal.h', 'include/xcb-internal.h',
'include/rofi.h', 'include/rofi.h',

View file

@ -45,7 +45,7 @@
#include <libgwater-xcb.h> #include <libgwater-xcb.h>
#include "xcb-internal.h" #include "display.h"
#include "settings.h" #include "settings.h"
#include "mode.h" #include "mode.h"
@ -95,6 +95,8 @@ unsigned int num_modi = 0;
/** Current selected mode */ /** Current selected mode */
unsigned int curr_switcher = 0; unsigned int curr_switcher = 0;
NkBindings *bindings = NULL;
/** Glib main loop. */ /** Glib main loop. */
GMainLoop *main_loop = NULL; GMainLoop *main_loop = NULL;
@ -146,7 +148,7 @@ static void teardown ( int pfd )
// Cleanup font setup. // Cleanup font setup.
textbox_cleanup ( ); textbox_cleanup ( );
x11_early_cleanup (); display_early_cleanup ();
// Cleanup view // Cleanup view
rofi_view_cleanup (); rofi_view_cleanup ();
@ -277,7 +279,7 @@ static void help ( G_GNUC_UNUSED int argc, char **argv )
printf ( "Global options:\n" ); printf ( "Global options:\n" );
print_options (); print_options ();
printf ( "\n" ); printf ( "\n" );
x11_dump_monitor_layout (); display_dump_monitor_layout ();
printf ( "\n" ); printf ( "\n" );
printf ( "Detected modi:\n" ); printf ( "Detected modi:\n" );
print_list_of_modi ( is_term ); print_list_of_modi ( is_term );
@ -399,7 +401,9 @@ static void cleanup ()
main_loop = NULL; main_loop = NULL;
} }
// Cleanup // Cleanup
xcb_stuff_wipe (); display_cleanup ();
nk_bindings_free ( bindings );
// Cleaning up memory allocated by the Xresources file. // Cleaning up memory allocated by the Xresources file.
config_xresource_free (); config_xresource_free ();
@ -785,7 +789,13 @@ int main ( int argc, char *argv[] )
TICK_N ( "Setup mainloop" ); TICK_N ( "Setup mainloop" );
if ( !x11_setup ( main_loop ) ) { bindings = nk_bindings_new ();
if ( !parse_keys_abe ( bindings ) ) {
cleanup ();
return EXIT_FAILURE;
}
if ( !display_setup ( main_loop, bindings ) ) {
g_warning ( "Connection has error" ); g_warning ( "Connection has error" );
cleanup (); cleanup ();
return EXIT_FAILURE; return EXIT_FAILURE;
@ -890,7 +900,7 @@ int main ( int argc, char *argv[] )
} }
textbox_setup (); textbox_setup ();
if ( !x11_late_setup () ) { if ( !display_late_setup () ) {
g_warning ( "Failed to properly finish display setup" ); g_warning ( "Failed to properly finish display setup" );
cleanup (); cleanup ();
return EXIT_FAILURE; return EXIT_FAILURE;

View file

@ -54,6 +54,7 @@
#include "rofi.h" #include "rofi.h"
#include "mode.h" #include "mode.h"
#include "display.h"
#include "xcb-internal.h" #include "xcb-internal.h"
#include "helper.h" #include "helper.h"
#include "helper-theme.h" #include "helper-theme.h"
@ -1649,7 +1650,7 @@ void rofi_view_hide ( void )
{ {
if ( CacheState.main_window != XCB_WINDOW_NONE ) { if ( CacheState.main_window != XCB_WINDOW_NONE ) {
xcb_unmap_window ( xcb->connection, CacheState.main_window ); xcb_unmap_window ( xcb->connection, CacheState.main_window );
x11_early_cleanup (); display_early_cleanup ();
} }
} }

View file

@ -49,6 +49,7 @@
#include <xcb/xkb.h> #include <xcb/xkb.h>
#include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-x11.h> #include <xkbcommon/xkbcommon-x11.h>
#include "display.h"
#include "xcb-internal.h" #include "xcb-internal.h"
#include "xcb.h" #include "xcb.h"
#include "settings.h" #include "settings.h"
@ -277,7 +278,7 @@ static void x11_build_monitor_layout_xinerama ()
free ( screens_reply ); free ( screens_reply );
} }
void x11_build_monitor_layout () static void x11_build_monitor_layout ()
{ {
if ( xcb->monitors ) { if ( xcb->monitors ) {
return; return;
@ -331,7 +332,7 @@ void x11_build_monitor_layout ()
free ( res_reply ); free ( res_reply );
} }
void x11_dump_monitor_layout ( void ) void display_dump_monitor_layout ( void )
{ {
int is_term = isatty ( fileno ( stdout ) ); int is_term = isatty ( fileno ( stdout ) );
printf ( "Monitor layout:\n" ); printf ( "Monitor layout:\n" );
@ -798,7 +799,7 @@ static void x11_create_frequently_used_atoms ( void )
} }
} }
gboolean x11_setup ( GMainLoop *main_loop ) gboolean display_setup ( GMainLoop *main_loop, NkBindings *bindings )
{ {
// Get DISPLAY, first env, then argument. // Get DISPLAY, first env, then argument.
// We never modify display_str content. // We never modify display_str content.
@ -879,8 +880,7 @@ gboolean x11_setup ( GMainLoop *main_loop )
required_map_parts, /* map */ required_map_parts, /* map */
&details ); &details );
xcb->bindings = nk_bindings_new (); xcb->bindings_seat = nk_bindings_seat_new ( bindings, XKB_CONTEXT_NO_FLAGS );
xcb->bindings_seat = nk_bindings_seat_new ( xcb->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 ); 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 ) { if ( keymap == NULL ) {
g_warning ( "Failed to get Keymap for current keyboard device." ); g_warning ( "Failed to get Keymap for current keyboard device." );
@ -894,11 +894,6 @@ gboolean x11_setup ( GMainLoop *main_loop )
nk_bindings_seat_update_keymap ( xcb->bindings_seat, keymap, state ); 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 // determine numlock mask so we can bind on keys with and without it
x11_create_frequently_used_atoms ( ); x11_create_frequently_used_atoms ( );
@ -997,7 +992,7 @@ static gboolean lazy_grab_keyboard ( G_GNUC_UNUSED gpointer data )
return G_SOURCE_CONTINUE; return G_SOURCE_CONTINUE;
} }
gboolean x11_late_setup ( void ) gboolean display_late_setup ( void )
{ {
x11_create_visual_and_colormap (); x11_create_visual_and_colormap ();
@ -1035,14 +1030,14 @@ xcb_window_t xcb_stuff_get_root_window ( void )
return xcb->screen->root; return xcb->screen->root;
} }
void x11_early_cleanup ( void ) void display_early_cleanup ( void )
{ {
release_keyboard ( ); release_keyboard ( );
release_pointer ( ); release_pointer ( );
xcb_flush ( xcb->connection ); xcb_flush ( xcb->connection );
} }
void xcb_stuff_wipe ( void ) void display_cleanup ( void )
{ {
if ( xcb->connection == NULL ) { if ( xcb->connection == NULL ) {
return; return;
@ -1051,7 +1046,6 @@ void xcb_stuff_wipe ( void )
g_debug ( "Cleaning up XCB and XKB" ); g_debug ( "Cleaning up XCB and XKB" );
nk_bindings_seat_free ( xcb->bindings_seat ); nk_bindings_seat_free ( xcb->bindings_seat );
nk_bindings_free ( xcb->bindings );
if ( xcb->sncontext != NULL ) { if ( xcb->sncontext != NULL ) {
sn_launchee_context_unref ( xcb->sncontext ); sn_launchee_context_unref ( xcb->sncontext );
xcb->sncontext = NULL; xcb->sncontext = NULL;