summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2017-06-01 14:20:36 +0200
committerDave Davenport <qball@gmpclient.org>2017-06-01 14:20:36 +0200
commitcdc8e462b8b0e890bf9d00759290328186a44c48 (patch)
tree1ab63df87700417c1286cf5b536606b6c77dbdac /source
parent45e76b781eb1a65afe3df75857f1b7847bb25e49 (diff)
parent1d99363ce99d3412f20604ea93a49c7e3ee02340 (diff)
Merge remote-tracking branch 'origin/master' into barview
Diffstat (limited to 'source')
-rw-r--r--source/dialogs/drun.c84
-rw-r--r--source/dialogs/window.c1
-rw-r--r--source/helper.c28
-rw-r--r--source/keyb.c4
-rw-r--r--source/mode.c1
-rw-r--r--source/rofi.c342
-rw-r--r--source/view.c216
-rw-r--r--source/widgets/listview.c2
-rw-r--r--source/widgets/scrollbar.c1
-rw-r--r--source/widgets/textbox.c21
-rw-r--r--source/xcb.c (renamed from source/x11-helper.c)474
-rw-r--r--source/xrmoptions.c1
12 files changed, 598 insertions, 577 deletions
diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c
index a10057e6..83aabef4 100644
--- a/source/dialogs/drun.c
+++ b/source/dialogs/drun.c
@@ -50,6 +50,7 @@
#include "history.h"
#include "dialogs/drun.h"
#include "nkutils-xdg-theme.h"
+#include "xcb.h"
#define DRUN_CACHE_FILE "rofi2.druncache"
@@ -89,9 +90,9 @@ typedef struct
unsigned int cmd_list_length_actual;
unsigned int history_length;
// List of disabled entries.
- GHashTable *disabled_entries;
- unsigned int disabled_entries_length;
- GThread *thread;
+ GHashTable *disabled_entries;
+ unsigned int disabled_entries_length;
+ GThread *thread;
} DRunModePrivateData;
struct RegexEvalArg
@@ -423,41 +424,44 @@ static void drun_icon_fetch ( gpointer data )
{
// as long as dr->icon is updated atomicly.. (is a pointer write atomic?)
// this should be fine running in another thread.
- GTimer *t = g_timer_new ();
- DRunModePrivateData *pd = (DRunModePrivateData*)data;
- for ( size_t i = 0; i < pd->cmd_list_length; i++ ) {
- DRunModeEntry *dr = &( pd->entry_list[i] );
- if ( dr->icon_name == NULL )
- continue;
- gchar *icon_path = nk_xdg_theme_get_icon ( pd->xdg_context, NULL, "Applications", dr->icon_name, 32, 1, TRUE );
- if ( icon_path == NULL ) {
- g_free(dr->icon_name);
- dr->icon_name = NULL;
- continue;
- }
- else
- g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Found Icon %s(%d): %s", dr->icon_name, 32, icon_path );
-
- if ( g_str_has_suffix ( icon_path, ".png" ) )
- dr->icon = cairo_image_surface_create_from_png(icon_path);
- else if ( g_str_has_suffix ( icon_path, ".svg" ) )
- dr->icon = cairo_image_surface_create_from_svg(icon_path, 32);
- else {
- g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Icon type not yet supported: %s", icon_path );
- char *r = dr->icon_name;
- dr->icon_name = NULL;
- g_free(r);
- }
- g_free(icon_path);
- // if ( (i%100) == 99 )
- {
-
- rofi_view_reload();
- }
- }
- rofi_view_reload();
- g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "elapsed: %f\n" , g_timer_elapsed ( t, NULL));
- g_timer_destroy ( t );
+ GTimer *t = g_timer_new ();
+ DRunModePrivateData *pd = (DRunModePrivateData *) data;
+ for ( size_t i = 0; i < pd->cmd_list_length; i++ ) {
+ DRunModeEntry *dr = &( pd->entry_list[i] );
+ if ( dr->icon_name == NULL ) {
+ continue;
+ }
+ gchar *icon_path = nk_xdg_theme_get_icon ( pd->xdg_context, NULL, "Applications", dr->icon_name, 32, 1, TRUE );
+ if ( icon_path == NULL ) {
+ g_free ( dr->icon_name );
+ dr->icon_name = NULL;
+ continue;
+ }
+ else{
+ g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Found Icon %s(%d): %s", dr->icon_name, 32, icon_path );
+ }
+
+ if ( g_str_has_suffix ( icon_path, ".png" ) ) {
+ dr->icon = cairo_image_surface_create_from_png ( icon_path );
+ }
+ else if ( g_str_has_suffix ( icon_path, ".svg" ) ) {
+ dr->icon = cairo_image_surface_create_from_svg ( icon_path, 32 );
+ }
+ else {
+ g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Icon type not yet supported: %s", icon_path );
+ char *r = dr->icon_name;
+ dr->icon_name = NULL;
+ g_free ( r );
+ }
+ g_free ( icon_path );
+ // if ( (i%100) == 99 )
+ {
+ rofi_view_reload ();
+ }
+ }
+ rofi_view_reload ();
+ g_log ( G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "elapsed: %f\n", g_timer_elapsed ( t, NULL ) );
+ g_timer_destroy ( t );
}
static int drun_mode_init ( Mode *sw )
@@ -531,7 +535,7 @@ static void drun_mode_destroy ( Mode *sw )
{
DRunModePrivateData *rmpd = (DRunModePrivateData *) mode_get_private_data ( sw );
if ( rmpd != NULL ) {
- if ( rmpd->thread ){
+ if ( rmpd->thread ) {
g_thread_join ( rmpd->thread );
rmpd->thread = NULL;
}
@@ -572,7 +576,7 @@ static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line,
{
DRunModePrivateData *pd = (DRunModePrivateData *) mode_get_private_data ( sw );
g_return_val_if_fail ( pd->entry_list != NULL, NULL );
- DRunModeEntry *dr = &( pd->entry_list[selected_line] );
+ DRunModeEntry *dr = &( pd->entry_list[selected_line] );
return dr->icon;
}
diff --git a/source/dialogs/window.c b/source/dialogs/window.c
index d19e1c61..f3276ba2 100644
--- a/source/dialogs/window.c
+++ b/source/dialogs/window.c
@@ -52,7 +52,6 @@
#include "settings.h"
#include "helper.h"
#include "widgets/textbox.h"
-#include "x11-helper.h"
#include "dialogs/window.h"
#define WINLIST 32
diff --git a/source/helper.c b/source/helper.c
index 5299ced3..e0a0563e 100644
--- a/source/helper.c
+++ b/source/helper.c
@@ -43,14 +43,14 @@
#include <sys/stat.h>
#include <pwd.h>
#include <ctype.h>
-#include <xcb/xcb.h>
#include <pango/pango.h>
#include <pango/pango-fontmap.h>
#include <pango/pangocairo.h>
+#include <librsvg/rsvg.h>
+#include "xcb.h"
#include "helper.h"
#include "helper-theme.h"
#include "settings.h"
-#include "x11-helper.h"
#include "rofi.h"
#include "view.h"
@@ -1024,3 +1024,27 @@ char *helper_get_theme_path ( const char *file )
}
return filename;
}
+
+cairo_surface_t* cairo_image_surface_create_from_svg ( const gchar* file, int height )
+{
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ RsvgHandle * handle;
+ RsvgDimensionData dimensions;
+
+ handle = rsvg_handle_new_from_file ( file, NULL );
+ rsvg_handle_get_dimensions ( handle, &dimensions );
+ double scale = (double) height / dimensions.height;
+ surface = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32,
+ (double) dimensions.width * scale,
+ (double) dimensions.height * scale );
+ cr = cairo_create ( surface );
+ cairo_scale ( cr, scale, scale );
+ rsvg_handle_render_cairo ( handle, cr );
+ cairo_destroy ( cr );
+
+ rsvg_handle_close ( handle, NULL );
+ g_object_unref ( handle );
+
+ return surface;
+}
diff --git a/source/keyb.c b/source/keyb.c
index 26837c05..a5a7ceb0 100644
--- a/source/keyb.c
+++ b/source/keyb.c
@@ -28,8 +28,6 @@
#include <config.h>
#include <string.h>
#include "rofi.h"
-#include "xkb.h"
-#include "xkb-internal.h"
#include "nkutils-bindings.h"
#include "xrmoptions.h"
@@ -140,7 +138,7 @@ void setup_abe ( void )
}
}
-static gboolean binding_trigger_action ( guint scope, gpointer user_data )
+static gboolean binding_trigger_action ( guint64 scope, gpointer user_data )
{
return rofi_view_trigger_action ( rofi_view_get_active (), scope, GPOINTER_TO_UINT ( user_data ) );
}
diff --git a/source/mode.c b/source/mode.c
index 5e070e3c..c8ccfa68 100644
--- a/source/mode.c
+++ b/source/mode.c
@@ -30,7 +30,6 @@
#include <string.h>
#include "rofi.h"
#include "xrmoptions.h"
-#include "x11-helper.h"
#include "mode.h"
// This one should only be in mode implementations.
diff --git a/source/rofi.c b/source/rofi.c
index 441edebf..9c52437c 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -39,11 +39,6 @@
#include <locale.h>
#include <gmodule.h>
#include <xcb/xcb.h>
-#include <xcb/xcb_aux.h>
-#include <xcb/xcb_ewmh.h>
-#include <xcb/xkb.h>
-#include <xkbcommon/xkbcommon.h>
-#include <xkbcommon/xkbcommon-x11.h>
#include <sys/types.h>
#include <glib-unix.h>
@@ -51,14 +46,12 @@
#include <libgwater-xcb.h>
#include "xcb-internal.h"
-#include "xkb-internal.h"
#include "settings.h"
#include "mode.h"
#include "rofi.h"
#include "helper.h"
#include "widgets/textbox.h"
-#include "x11-helper.h"
#include "xrmoptions.h"
#include "dialogs/dialogs.h"
@@ -87,11 +80,6 @@ void rofi_add_error_message ( GString *str )
{
list_of_error_msgs = g_list_append ( list_of_error_msgs, str );
}
-/** global structure holding the keyboard status */
-struct xkb_stuff xkb = {
- .xcb_connection = NULL,
- .bindings = NULL,
-};
/** Path to the configuration file */
G_MODULE_EXPORT char *config_path = NULL;
@@ -109,8 +97,6 @@ unsigned int curr_switcher = 0;
/** Glib main loop. */
GMainLoop *main_loop = NULL;
-/** GWater xcb source, signalling events from the X server */
-GWaterXcbSource *main_loop_source = NULL;
/** Flag indicating we are in dmenu mode. */
static int dmenu_mode = FALSE;
@@ -152,21 +138,6 @@ static int switcher_get ( const char *name )
}
/**
- * Do needed steps to start showing the gui
- */
-static int setup ()
-{
- // Create pid file
- int pfd = create_pid_file ( pidfile );
- if ( pfd >= 0 ) {
- // Request truecolor visual.
- x11_create_visual_and_colormap ( );
- textbox_setup ();
- }
- return pfd;
-}
-
-/**
* Teardown the gui.
*/
static void teardown ( int pfd )
@@ -175,9 +146,7 @@ static void teardown ( int pfd )
// Cleanup font setup.
textbox_cleanup ( );
- // Release the window.
- release_keyboard ( );
- release_pointer ( );
+ x11_early_cleanup ();
// Cleanup view
rofi_view_cleanup ();
@@ -426,18 +395,11 @@ static void cleanup ()
}
rofi_view_workers_finalize ();
if ( main_loop != NULL ) {
- if ( main_loop_source ) {
- g_water_xcb_source_free ( main_loop_source );
- }
g_main_loop_unref ( main_loop );
main_loop = NULL;
}
- // XKB Cleanup
- //
- nk_bindings_free ( xkb.bindings );
-
// Cleanup
- xcb_stuff_wipe ( xcb );
+ xcb_stuff_wipe ();
// Cleaning up memory allocated by the Xresources file.
config_xresource_free ();
@@ -629,74 +591,9 @@ static gboolean setup_modi ( void )
return FALSE;
}
-/**
- * Process X11 events in the main-loop (gui-thread) of the application.
- */
-static void main_loop_x11_event_handler_view ( xcb_generic_event_t *ev )
-{
- RofiViewState *state = rofi_view_get_active ();
- if ( state != NULL ) {
- rofi_view_itterrate ( state, ev, &xkb );
- if ( rofi_view_get_completed ( state ) ) {
- // This menu is done.
- rofi_view_finalize ( state );
- // cleanup
- if ( rofi_view_get_active () == NULL ) {
- g_main_loop_quit ( main_loop );
- }
- }
- }
-}
-static gboolean main_loop_x11_event_handler ( xcb_generic_event_t *ev, G_GNUC_UNUSED gpointer data )
+void rofi_quit_main_loop ( void )
{
- if ( ev == NULL ) {
- int status = xcb_connection_has_error ( xcb->connection );
- if ( status > 0 ) {
- g_warning ( "The XCB connection to X server had a fatal error: %d", status );
- g_main_loop_quit ( main_loop );
- return G_SOURCE_REMOVE;
- }
- else {
- g_warning ( "main_loop_x11_event_handler: ev == NULL, status == %d", status );
- return G_SOURCE_CONTINUE;
- }
- }
- uint8_t type = ev->response_type & ~0x80;
- if ( type == xkb.first_event ) {
- switch ( ev->pad0 )
- {
- case XCB_XKB_MAP_NOTIFY:
- {
- struct xkb_keymap *keymap = xkb_x11_keymap_new_from_device ( nk_bindings_get_context ( xkb.bindings ), xcb->connection, xkb.device_id, 0 );
- struct xkb_state *state = xkb_x11_state_new_from_device ( keymap, xcb->connection, xkb.device_id );
- nk_bindings_update_keymap ( xkb.bindings, keymap, state );
- xkb_keymap_unref ( keymap );
- xkb_state_unref ( state );
- break;
- }
- case XCB_XKB_STATE_NOTIFY:
- {
- xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *) ev;
- nk_bindings_update_mask ( xkb.bindings,
- ksne->baseMods,
- ksne->latchedMods,
- ksne->lockedMods,
- ksne->baseGroup,
- ksne->latchedGroup,
- ksne->lockedGroup );
- xcb_generic_event_t dev;
- dev.response_type = 0;
- main_loop_x11_event_handler_view ( &dev );
- break;
- }
- }
- return G_SOURCE_CONTINUE;
- }
- if ( xcb->sndisplay != NULL ) {
- sn_xcb_display_process_event ( xcb->sndisplay, ev );
- }
- main_loop_x11_event_handler_view ( ev );
- return G_SOURCE_CONTINUE;
+ g_main_loop_quit ( main_loop );
}
static gboolean main_loop_signal_handler_int ( G_GNUC_UNUSED gpointer data )
@@ -706,55 +603,6 @@ static gboolean main_loop_signal_handler_int ( G_GNUC_UNUSED gpointer data )
return G_SOURCE_CONTINUE;
}
-/** X server error depth. to handle nested errors. */
-static int error_trap_depth = 0;
-static void error_trap_push ( G_GNUC_UNUSED SnDisplay *display, G_GNUC_UNUSED xcb_connection_t *xdisplay )
-{
- ++error_trap_depth;
-}
-
-static void error_trap_pop ( G_GNUC_UNUSED SnDisplay *display, xcb_connection_t *xdisplay )
-{
- if ( error_trap_depth == 0 ) {
- g_warning ( "Error trap underflow!" );
- exit ( EXIT_FAILURE );
- }
-
- xcb_flush ( xdisplay );
- --error_trap_depth;
-}
-/** Retry count of grabbing keyboard. */
-unsigned int lazy_grab_retry_count_kb = 0;
-/** Retry count of grabbing pointer. */
-unsigned int lazy_grab_retry_count_pt = 0;
-static gboolean lazy_grab_pointer ( G_GNUC_UNUSED gpointer data )
-{
- // After 5 sec.
- if ( lazy_grab_retry_count_pt > ( 5 * 1000 ) ) {
- g_warning ( "Failed to grab pointer after %u times. Giving up.", lazy_grab_retry_count_pt );
- return G_SOURCE_REMOVE;
- }
- if ( take_pointer ( xcb_stuff_get_root_window ( xcb ), 0 ) ) {
- return G_SOURCE_REMOVE;
- }
- lazy_grab_retry_count_pt++;
- return G_SOURCE_CONTINUE;
-}
-static gboolean lazy_grab_keyboard ( G_GNUC_UNUSED gpointer data )
-{
- // After 5 sec.
- if ( lazy_grab_retry_count_kb > ( 5 * 1000 ) ) {
- g_warning ( "Failed to grab keyboard after %u times. Giving up.", lazy_grab_retry_count_kb );
- g_main_loop_quit ( main_loop );
- return G_SOURCE_REMOVE;
- }
- if ( take_keyboard ( xcb_stuff_get_root_window ( xcb ), 0 ) ) {
- return G_SOURCE_REMOVE;
- }
- lazy_grab_retry_count_kb++;
- return G_SOURCE_CONTINUE;
-}
-
static gboolean startup ( G_GNUC_UNUSED gpointer data )
{
TICK_N ( "Startup" );
@@ -766,41 +614,10 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data )
if ( find_arg ( "-normal-window" ) >= 0 ) {
window_flags |= MENU_NORMAL_WINDOW;
}
-
- /**
- * Create window (without showing)
- */
- // 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.
- if ( ( window_flags & MENU_NORMAL_WINDOW ) == 0 ) {
- if ( find_arg ( "-no-lazy-grab" ) >= 0 ) {
- if ( !take_keyboard ( xcb_stuff_get_root_window ( xcb ), 500 ) ) {
- g_warning ( "Failed to grab keyboard, even after %d uS.", 500 * 1000 );
- g_main_loop_quit ( main_loop );
- return G_SOURCE_REMOVE;
- }
- if ( !take_pointer ( xcb_stuff_get_root_window ( xcb ), 100 ) ) {
- g_warning ( "Failed to grab mouse pointer, even after %d uS.", 100 * 1000 );
- }
- }
- else {
- if ( !take_keyboard ( xcb_stuff_get_root_window ( xcb ), 0 ) ) {
- g_timeout_add ( 1, lazy_grab_keyboard, NULL );
- }
- if ( !take_pointer ( xcb_stuff_get_root_window ( xcb ), 0 ) ) {
- g_timeout_add ( 1, lazy_grab_pointer, NULL );
- }
- }
- }
TICK_N ( "Grab keyboard" );
__create_window ( window_flags );
TICK_N ( "Create Window" );
// Parse the keybindings.
- if ( !parse_keys_abe ( xkb.bindings ) ) {
- // Error dialog
- return G_SOURCE_REMOVE;
- }
TICK_N ( "Parse ABE" );
// Sanity check
config_sanity_check ( );
@@ -960,143 +777,21 @@ int main ( int argc, char *argv[] )
return EXIT_FAILURE;
}
- // Get DISPLAY, first env, then argument.
- // We never modify display_str content.
- char *display_str = ( char *) g_getenv ( "DISPLAY" );
- find_arg_str ( "-display", &display_str );
-
- xcb->connection = xcb_connect ( display_str, &xcb->screen_nbr );
- if ( xcb_connection_has_error ( xcb->connection ) ) {
- g_warning ( "Failed to open display: %s", display_str );
- cleanup ();
- return EXIT_FAILURE;
- }
-
- TICK_N ( "Open Display" );
rofi_collect_modi ();
rofi_collect_modi_setup ();
TICK_N ( "Collect MODI" );
- xcb->screen = xcb_aux_get_screen ( xcb->connection, xcb->screen_nbr );
-
- x11_build_monitor_layout ();
-
- xcb_intern_atom_cookie_t *ac = xcb_ewmh_init_atoms ( xcb->connection, &xcb->ewmh );
- xcb_generic_error_t *errors = NULL;
- xcb_ewmh_init_atoms_replies ( &xcb->ewmh, ac, &errors );
- if ( errors ) {
- g_warning ( "Failed to create EWMH atoms" );
- free ( errors );
- }
- // Discover the current active window manager.
- x11_helper_discover_window_manager ();
- TICK_N ( "Setup XCB" );
-
- if ( xkb_x11_setup_xkb_extension ( xcb->connection, XKB_X11_MIN_MAJOR_XKB_VERSION, XKB_X11_MIN_MINOR_XKB_VERSION,
- XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS, NULL, NULL, &xkb.first_event, NULL ) < 0 ) {
- g_warning ( "cannot setup XKB extension!" );
- cleanup ();
- return EXIT_FAILURE;
- }
-
- struct xkb_context *xkb_context = xkb_context_new ( XKB_CONTEXT_NO_FLAGS );
- if ( xkb_context == NULL ) {
- g_warning ( "cannot create XKB context!" );
- cleanup ();
- return EXIT_FAILURE;
- }
- xkb.xcb_connection = xcb->connection;
-
- xkb.device_id = xkb_x11_get_core_keyboard_device_id ( xcb->connection );
-
- enum
- {
- required_events =
- ( XCB_XKB_EVENT_TYPE_NEW_KEYBOARD_NOTIFY |
- XCB_XKB_EVENT_TYPE_MAP_NOTIFY |
- XCB_XKB_EVENT_TYPE_STATE_NOTIFY ),
-
- required_nkn_details =
- ( XCB_XKB_NKN_DETAIL_KEYCODES ),
-
- required_map_parts =
- ( XCB_XKB_MAP_PART_KEY_TYPES |
- XCB_XKB_MAP_PART_KEY_SYMS |
- XCB_XKB_MAP_PART_MODIFIER_MAP |
- XCB_XKB_MAP_PART_EXPLICIT_COMPONENTS |
- XCB_XKB_MAP_PART_KEY_ACTIONS |
- XCB_XKB_MAP_PART_VIRTUAL_MODS |
- XCB_XKB_MAP_PART_VIRTUAL_MOD_MAP ),
-
- required_state_details =
- ( XCB_XKB_STATE_PART_MODIFIER_BASE |
- XCB_XKB_STATE_PART_MODIFIER_LATCH |
- XCB_XKB_STATE_PART_MODIFIER_LOCK |
- XCB_XKB_STATE_PART_GROUP_BASE |
- XCB_XKB_STATE_PART_GROUP_LATCH |
- XCB_XKB_STATE_PART_GROUP_LOCK ),
- };
-
- static const xcb_xkb_select_events_details_t details = {
- .affectNewKeyboard = required_nkn_details,
- .newKeyboardDetails = required_nkn_details,
- .affectState = required_state_details,
- .stateDetails = required_state_details,
- };
- xcb_xkb_select_events ( xcb->connection, xkb.device_id, required_events, /* affectWhich */
- 0, /* clear */
- required_events, /* selectAll */
- required_map_parts, /* affectMap */
- required_map_parts, /* map */
- &details );
-
- struct xkb_keymap *keymap = xkb_x11_keymap_new_from_device ( xkb_context, xcb->connection, xkb.device_id, XKB_KEYMAP_COMPILE_NO_FLAGS );
- if ( keymap == NULL ) {
- g_warning ( "Failed to get Keymap for current keyboard device." );
- cleanup ();
- return EXIT_FAILURE;
- }
- struct xkb_state *state = xkb_x11_state_new_from_device ( keymap, xcb->connection, xkb.device_id );
- if ( state == NULL ) {
- g_warning ( "Failed to get state object for current keyboard device." );
- cleanup ();
- return EXIT_FAILURE;
- }
-
- xkb.bindings = nk_bindings_new ( xkb_context, keymap, state );
-
- if ( xcb_connection_has_error ( xcb->connection ) ) {
- g_warning ( "Connection has error" );
- cleanup ();
- return EXIT_FAILURE;
- }
- x11_setup ();
- TICK_N ( "Setup xkb" );
- if ( xcb_connection_has_error ( xcb->connection ) ) {
- g_warning ( "Connection has error" );
- cleanup ();
- return EXIT_FAILURE;
- }
main_loop = g_main_loop_new ( NULL, FALSE );
TICK_N ( "Setup mainloop" );
- // startup not.
- xcb->sndisplay = sn_xcb_display_new ( xcb->connection, error_trap_push, error_trap_pop );
- if ( xcb_connection_has_error ( xcb->connection ) ) {
- g_warning ( "Connection has error" );
- cleanup ();
- return EXIT_FAILURE;
- }
- if ( xcb->sndisplay != NULL ) {
- xcb->sncontext = sn_launchee_context_new_from_environment ( xcb->sndisplay, xcb->screen_nbr );
- }
- if ( xcb_connection_has_error ( xcb->connection ) ) {
+ if ( !x11_setup ( main_loop ) ) {
g_warning ( "Connection has error" );
cleanup ();
return EXIT_FAILURE;
}
- TICK_N ( "Startup Notification" );
+ TICK_N ( "Setup Display" );
+
// Setup keybinding
setup_abe ();
TICK_N ( "Setup abe" );
@@ -1184,23 +879,30 @@ int main ( int argc, char *argv[] )
if ( find_arg_uint ( "-record-screenshots", &interval ) ) {
g_timeout_add ( 1000 / (double) interval, record, NULL );
}
- main_loop_source = g_water_xcb_source_new_for_connection ( NULL, xcb->connection, main_loop_x11_event_handler, NULL, NULL );
-
- TICK_N ( "X11 Setup " );
rofi_view_workers_initialize ();
+ // Create pid file
+ int pfd = create_pid_file ( pidfile );
+ if ( pfd < 0 ) {
+ cleanup ();
+ return EXIT_FAILURE;
+ }
+ textbox_setup ();
+
+ if ( !x11_late_setup () ) {
+ g_warning ( "Failed to properly finish display setup" );
+ cleanup ();
+ return EXIT_FAILURE;
+ }
+ TICK_N ( "Setup late Display" );
+
// Setup signal handling sources.
// SIGINT
g_unix_signal_add ( SIGINT, main_loop_signal_handler_int, NULL );
g_idle_add ( startup, NULL );
- // Pidfile + visuals
- int pfd = setup ();
- if ( pfd < 0 ) {
- return EXIT_FAILURE;
- }
// Start mainloop.
g_main_loop_run ( main_loop );
teardown ( pfd );
diff --git a/source/view.c b/source/view.c
index 5020eb00..824d2300 100644
--- a/source/view.c
+++ b/source/view.c
@@ -55,10 +55,8 @@
#include "rofi.h"
#include "mode.h"
#include "xcb-internal.h"
-#include "xkb-internal.h"
#include "helper.h"
#include "helper-theme.h"
-#include "x11-helper.h"
#include "xrmoptions.h"
#include "dialogs/dialogs.h"
@@ -653,7 +651,7 @@ void __create_window ( MenuFlags menu_flags )
};
xcb_window_t box_window = xcb_generate_id ( xcb->connection );
- xcb_void_cookie_t cc = xcb_create_window_checked ( xcb->connection, depth->depth, box_window, xcb_stuff_get_root_window ( xcb ),
+ xcb_void_cookie_t cc = xcb_create_window_checked ( xcb->connection, depth->depth, box_window, xcb_stuff_get_root_window ( ),
0, 0, 200, 100, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
visual->visual_id, selmask, selval );
xcb_generic_error_t *error;
@@ -906,7 +904,7 @@ static void update_callback ( textbox *t, unsigned int index, void *udata, TextB
else{
list = pango_attr_list_new ();
}
- int icon_height = textbox_get_font_height ( t );
+ int icon_height = textbox_get_font_height ( t );
cairo_surface_t *icon = mode_get_icon ( state->sw, state->line_map[index], icon_height );
textbox_icon ( t, icon );
@@ -974,40 +972,6 @@ void rofi_view_update ( RofiViewState *state, gboolean qr )
}
}
-/**
- * @param state Internal state of the menu.
- * @param xse X selection event.
- *
- * Handle paste event.
- */
-static void rofi_view_paste ( RofiViewState *state, xcb_selection_notify_event_t *xse )
-{
- if ( xse->property == XCB_ATOM_NONE ) {
- g_warning ( "Failed to convert selection" );
- }
- else if ( xse->property == xcb->ewmh.UTF8_STRING ) {
- gchar *text = window_get_text_prop ( CacheState.main_window, xcb->ewmh.UTF8_STRING );
- if ( text != NULL && text[0] != '\0' ) {
- unsigned int dl = strlen ( text );
- // Strip new line
- for ( unsigned int i = 0; i < dl; i++ ) {
- if ( text[i] == '\n' ) {
- dl = i;
- }
- }
- // Insert string move cursor.
- textbox_insert ( state->text, state->text->cursor, text, dl );
- textbox_cursor ( state->text, state->text->cursor + g_utf8_strlen ( text, -1 ) );
- // Force a redraw and refiltering of the text.
- state->refilter = TRUE;
- }
- g_free ( text );
- }
- else {
- g_warning ( "Failed" );
- }
-}
-
static void _rofi_view_reload_row ( RofiViewState *state )
{
g_free ( state->line_map );
@@ -1384,122 +1348,83 @@ gboolean rofi_view_trigger_action ( RofiViewState *state, BindingsScope scope, g
return FALSE;
}
-void rofi_view_itterrate ( RofiViewState *state, xcb_generic_event_t *event, xkb_stuff *xkb )
+void rofi_view_handle_text ( RofiViewState *state, char *text )
{
- switch ( event->response_type & ~0x80 )
- {
- case XCB_CONFIGURE_NOTIFY:
- {
- xcb_configure_notify_event_t *xce = (xcb_configure_notify_event_t *) event;
- if ( xce->window == CacheState.main_window ) {
- if ( state->x != xce->x || state->y != xce->y ) {
- state->x = xce->x;
- state->y = xce->y;
- widget_queue_redraw ( WIDGET ( state->main_window ) );
- }
- if ( state->width != xce->width || state->height != xce->height ) {
- state->width = xce->width;
- state->height = xce->height;
-
- cairo_destroy ( CacheState.edit_draw );
- cairo_surface_destroy ( CacheState.edit_surf );
-
- xcb_free_pixmap ( xcb->connection, CacheState.edit_pixmap );
- CacheState.edit_pixmap = xcb_generate_id ( xcb->connection );
- xcb_create_pixmap ( xcb->connection, depth->depth, CacheState.edit_pixmap, CacheState.main_window,
- state->width, state->height );
-
- CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, state->width, state->height );
- CacheState.edit_draw = cairo_create ( CacheState.edit_surf );
- g_debug ( "Re-size window based external request: %d %d", state->width, state->height );
- widget_resize ( WIDGET ( state->main_window ), state->width, state->height );
- }
- }
- break;
- }
- case XCB_MOTION_NOTIFY:
- {
- if ( config.click_to_exit == TRUE ) {
- state->mouse_seen = TRUE;
- }
- xcb_motion_notify_event_t xme = *( (xcb_motion_notify_event_t *) event );
- state->mouse.x = xme.event_x;
- state->mouse.y = xme.event_y;
- if ( state->mouse.motion_target != NULL ) {
- gint x = state->mouse.x;
- gint y = state->mouse.y;
- widget_xy_to_relative ( state->mouse.motion_target, &x, &y );
- widget_motion_notify ( state->mouse.motion_target, x, y );
- }
- break;
- }
- case XCB_BUTTON_PRESS:
- {
- xcb_button_press_event_t *bpe = (xcb_button_press_event_t *) event;
- state->mouse.x = bpe->event_x;
- state->mouse.y = bpe->event_y;
- nk_bindings_handle_button ( xkb->bindings, bpe->detail, NK_BINDINGS_BUTTON_STATE_PRESS, bpe->time );
- break;
- }
- case XCB_BUTTON_RELEASE:
- {
- xcb_button_release_event_t *bre = (xcb_button_release_event_t *) event;
- nk_bindings_handle_button ( xkb->bindings, bre->detail, NK_BINDINGS_BUTTON_STATE_RELEASE, bre->time );
- if ( config.click_to_exit == TRUE ) {
- if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == 0 ) {
- if ( ( state->mouse_seen == FALSE ) && ( bre->event != CacheState.main_window ) ) {
- state->quit = TRUE;
- state->retv = MENU_CANCEL;
- }
- }
- state->mouse_seen = FALSE;
- }
- break;
+ if ( textbox_append_text ( state->text, text, strlen ( text ) ) ) {
+ state->refilter = TRUE;
}
- // Paste event.
- case XCB_SELECTION_NOTIFY:
- rofi_view_paste ( state, (xcb_selection_notify_event_t *) event );
- break;
- case XCB_KEYMAP_NOTIFY:
- {
- xcb_keymap_notify_event_t *kne = (xcb_keymap_notify_event_t *) event;
- for ( gint32 by = 0; by < 31; ++by ) {
- for ( gint8 bi = 0; bi < 7; ++bi ) {
- if ( kne->keys[by] & ( 1 << bi ) ) {
- // X11 keycodes starts at 8
- nk_bindings_handle_key ( xkb->bindings, ( 8 * by + bi ) + 8, NK_BINDINGS_KEY_STATE_PRESSED );
- }
- }
- }
- break;
+}
+
+void rofi_view_handle_mouse_motion( RofiViewState *state, gint x, gint y )
+{
+ state->mouse.x = x;
+ state->mouse.y = y;
+ if ( state->mouse.motion_target != NULL ) {
+ widget_xy_to_relative ( state->mouse.motion_target, &x, &y );
+ widget_motion_notify ( state->mouse.motion_target, x, y );
}
- case XCB_KEY_PRESS:
- {
- xcb_key_press_event_t *xkpe = (xcb_key_press_event_t *) event;
- gchar *text;
+}
- text = nk_bindings_handle_key ( xkb->bindings, xkpe->detail, NK_BINDINGS_KEY_STATE_PRESS );
- if ( ( text != NULL