Remove normal window global.

This commit is contained in:
Dave Davenport 2016-02-10 19:40:19 +01:00
parent 2cd8888d2c
commit fdb4c99456
8 changed files with 100 additions and 67 deletions

View File

@ -1,12 +1,15 @@
1.0.0 (unreleased): 1.0.0 (unreleased):
New features: New features:
- Have separate config file. - Have separate config file.
- Use GlibMainLoop.
- Blinking cursor.
Bug fixes: Bug fixes:
- Fix subpixel rendering. (#303) - Fix subpixel rendering. (#303)
- Fix basic tests on OpenBSD (#272) - Fix basic tests on OpenBSD (#272)
- Fix wrong use of memcpy (thx to Jasperia). - Fix wrong use of memcpy (thx to Jasperia).
- Work around for sigwaitinfo on OpenBSD. - Work around for sigwaitinfo on OpenBSD.
- Ignore invalid (non-utf8) in dmenu mode. - Ignore invalid (non-utf8) in dmenu mode.
- Glib signal handling.
0.15.12: 0.15.12:
New features: New features:

View File

@ -42,15 +42,15 @@ typedef struct
typedef enum typedef enum
{ {
TB_AUTOHEIGHT = 1 << 0, TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1, TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16, TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17, TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18, TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19, TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20, TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21, TB_WRAP = 1 << 21,
TB_PASSWORD = 1 << 22, TB_PASSWORD = 1 << 22,
} TextboxFlags; } TextboxFlags;
typedef enum typedef enum

View File

@ -65,6 +65,8 @@ typedef struct RofiViewState
// Sidebar view // Sidebar view
ssize_t num_modi; ssize_t num_modi;
textbox **modi; textbox **modi;
MenuFlags menu_flags;
// Handlers. // Handlers.
void ( *x11_event_loop )( struct RofiViewState *state, XEvent *ev ); void ( *x11_event_loop )( struct RofiViewState *state, XEvent *ev );
void ( *finalize )( struct RofiViewState *state ); void ( *finalize )( struct RofiViewState *state );

View File

@ -15,9 +15,11 @@ typedef struct RofiViewState RofiViewState;
typedef enum typedef enum
{ {
/** Create a menu for entering text */ /** Create a menu for entering text */
MENU_NORMAL = 0, MENU_NORMAL = 0,
/** Create a menu for entering passwords */ /** Create a menu for entering passwords */
MENU_PASSWORD = 1 MENU_PASSWORD = 1,
/** Create amanaged window. */
MENU_NORMAL_WINDOW = 2,
} MenuFlags; } MenuFlags;
/** /**
@ -146,4 +148,17 @@ void rofi_view_cleanup ( void );
void rofi_view_call_thread ( gpointer data, gpointer user_data ); void rofi_view_call_thread ( gpointer data, gpointer user_data );
/** @} */ /** @} */
/***
* @defgroup ViewThreadPool ViewThreadPool
* @ingroup View
*
* The view can (optionally) keep a set of worker threads around to parallize work.
* This includes filtering and sorting.
*
* @{
*/
void rofi_view_workers_initialize ( void );
void rofi_view_workers_finalize ( void );
/**@}*/
#endif #endif

View File

@ -382,6 +382,9 @@ int dmenu_switcher_dialog ( void )
if ( find_arg ( "-password" ) >= 0 ) { if ( find_arg ( "-password" ) >= 0 ) {
menu_flags |= MENU_PASSWORD; menu_flags |= MENU_PASSWORD;
} }
if ( find_arg ( "-normal-window" ) >= 0 ) {
menu_flags |= MENU_NORMAL_WINDOW;
}
/* copy filter string */ /* copy filter string */
input = g_strdup ( config.filter ); input = g_strdup ( config.filter );

View File

@ -63,21 +63,19 @@
gboolean daemon_mode = FALSE; gboolean daemon_mode = FALSE;
// Pidfile. // Pidfile.
char *pidfile = NULL; char *pidfile = NULL;
const char *cache_dir = NULL; const char *cache_dir = NULL;
SnDisplay *sndisplay = NULL; SnDisplay *sndisplay = NULL;
SnLauncheeContext *sncontext = NULL; SnLauncheeContext *sncontext = NULL;
Display *display = NULL; Display *display = NULL;
char *display_str = NULL; char *display_str = NULL;
char *config_path = NULL; char *config_path = NULL;
unsigned int normal_window_mode = FALSE;
// Array of modi. // Array of modi.
Mode **modi = NULL; Mode **modi = NULL;
unsigned int num_modi = 0; unsigned int num_modi = 0;
// Current selected switcher. // Current selected switcher.
unsigned int curr_switcher = 0; unsigned int curr_switcher = 0;
GThreadPool *tpool = NULL;
GMainLoop *main_loop = NULL; GMainLoop *main_loop = NULL;
GSource *main_loop_source = NULL; GSource *main_loop_source = NULL;
gboolean quiet = FALSE; gboolean quiet = FALSE;
@ -337,10 +335,7 @@ static int grab_global_keybindings ()
*/ */
static void cleanup () static void cleanup ()
{ {
if ( tpool ) { rofi_view_workers_finalize ();
g_thread_pool_free ( tpool, TRUE, FALSE );
tpool = NULL;
}
if ( main_loop != NULL ) { if ( main_loop != NULL ) {
if ( main_loop_source ) { if ( main_loop_source ) {
g_source_destroy ( main_loop_source ); g_source_destroy ( main_loop_source );
@ -774,28 +769,9 @@ int main ( int argc, char *argv[] )
return show_error_message ( msg, markup ); return show_error_message ( msg, markup );
} }
// Create thread pool rofi_view_workers_initialize ();
GError *error = NULL;
tpool = g_thread_pool_new ( rofi_view_call_thread, NULL, config.threads, FALSE, &error );
if ( error == NULL ) {
// Idle threads should stick around for a max of 60 seconds.
g_thread_pool_set_max_idle_time ( 60000 );
// We are allowed to have
g_thread_pool_set_max_threads ( tpool, config.threads, &error );
}
// If error occured during setup of pool, tell user and exit.
if ( error != NULL ) {
char *msg = g_strdup_printf ( "Failed to setup thread pool: '%s'", error->message );
show_error_message ( msg, FALSE );
g_free ( msg );
g_error_free ( error );
return EXIT_FAILURE;
}
TICK_N ( "Setup Threadpool" );
// Dmenu mode. // Dmenu mode.
if ( dmenu_mode == TRUE ) { if ( dmenu_mode == TRUE ) {
normal_window_mode = find_arg ( "-normal-window" ) >= 0;
// force off sidebar mode: // force off sidebar mode:
config.sidebar_mode = FALSE; config.sidebar_mode = FALSE;
int retv = run_dmenu (); int retv = run_dmenu ();

View File

@ -66,12 +66,16 @@
#include "view.h" #include "view.h"
#include "view-internal.h" #include "view-internal.h"
// TODO get rid of num_modi and modi, use an accessor.
extern unsigned int num_modi;
extern Mode **modi;
// What todo with these.
extern Display *display; extern Display *display;
extern unsigned int num_modi;
extern Mode **modi;
extern SnDisplay *sndisplay; extern SnDisplay *sndisplay;
extern SnLauncheeContext *sncontext; extern SnLauncheeContext *sncontext;
extern GThreadPool *tpool;
GThreadPool *tpool = NULL;
RofiViewState *current_active_menu = NULL; RofiViewState *current_active_menu = NULL;
Window main_window = None; Window main_window = None;
@ -82,7 +86,6 @@ XIM xim;
XIC xic; XIC xic;
Colormap map = None; Colormap map = None;
XVisualInfo vinfo; XVisualInfo vinfo;
extern unsigned int normal_window_mode;
static char * get_matching_state ( void ) static char * get_matching_state ( void )
{ {
@ -382,7 +385,7 @@ static void check_is_ascii ( thread_state *t, G_GNUC_UNUSED gpointer user_data )
g_mutex_unlock ( t->mutex ); g_mutex_unlock ( t->mutex );
} }
static Window __create_window ( Display *display ) static Window __create_window ( Display *display, MenuFlags menu_flags )
{ {
XSetWindowAttributes attr; XSetWindowAttributes attr;
attr.colormap = map; attr.colormap = map;
@ -425,7 +428,7 @@ static Window __create_window ( Display *display )
cairo_font_options_destroy ( fo ); cairo_font_options_destroy ( fo );
// // make it an unmanaged window // // make it an unmanaged window
if ( !normal_window_mode && !config.fullscreen ) { if ( ( ( menu_flags & MENU_NORMAL_WINDOW ) == 0 ) && !config.fullscreen ) {
window_set_atom_prop ( display, box, netatoms[_NET_WM_STATE], &netatoms[_NET_WM_STATE_ABOVE], 1 ); window_set_atom_prop ( display, box, netatoms[_NET_WM_STATE], &netatoms[_NET_WM_STATE_ABOVE], 1 );
XSetWindowAttributes sattr = { .override_redirect = True }; XSetWindowAttributes sattr = { .override_redirect = True };
XChangeWindowAttributes ( display, box, CWOverrideRedirect, &sattr ); XChangeWindowAttributes ( display, box, CWOverrideRedirect, &sattr );
@ -1212,10 +1215,14 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, XEvent *ev )
} }
} }
else if ( ev->type == FocusIn ) { else if ( ev->type == FocusIn ) {
take_keyboard ( display, main_window ); if ( ( state->menu_flags & MENU_NORMAL_WINDOW ) == 0 ) {
take_keyboard ( display, main_window );
}
} }
else if ( ev->type == FocusOut ) { else if ( ev->type == FocusOut ) {
release_keyboard ( display ); if ( ( state->menu_flags & MENU_NORMAL_WINDOW ) == 0 ) {
release_keyboard ( display );
}
} }
// Handle event. // Handle event.
else if ( ev->type == Expose ) { else if ( ev->type == Expose ) {
@ -1387,6 +1394,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
{ {
TICK (); TICK ();
RofiViewState *state = __rofi_view_state_create (); RofiViewState *state = __rofi_view_state_create ();
state->menu_flags = menu_flags;
state->sw = sw; state->sw = sw;
state->selected_line = UINT32_MAX; state->selected_line = UINT32_MAX;
state->retv = MENU_CANCEL; state->retv = MENU_CANCEL;
@ -1446,19 +1454,21 @@ RofiViewState *rofi_view_create ( Mode *sw,
// Try to grab the keyboard as early as possible. // Try to grab the keyboard as early as possible.
// We grab this using the rootwindow (as dmenu does it). // We grab this using the rootwindow (as dmenu does it).
// this seems to result in the smallest delay for most people. // this seems to result in the smallest delay for most people.
int has_keyboard = take_keyboard ( display, DefaultRootWindow ( display ) ); if ( ( menu_flags & MENU_NORMAL_WINDOW ) == 0 ) {
int has_keyboard = take_keyboard ( display, DefaultRootWindow ( display ) );
if ( !has_keyboard ) { if ( !has_keyboard ) {
fprintf ( stderr, "Failed to grab keyboard, even after %d uS.", 500 * 1000 ); fprintf ( stderr, "Failed to grab keyboard, even after %d uS.", 500 * 1000 );
// Break off. // Break off.
rofi_view_free ( state ); rofi_view_free ( state );
return NULL; return NULL;
}
} }
TICK_N ( "Grab keyboard" ); TICK_N ( "Grab keyboard" );
// main window isn't explicitly destroyed in case we switch modes. Reusing it prevents flicker // main window isn't explicitly destroyed in case we switch modes. Reusing it prevents flicker
XWindowAttributes attr; XWindowAttributes attr;
if ( main_window == None || XGetWindowAttributes ( display, main_window, &attr ) == 0 ) { if ( main_window == None || XGetWindowAttributes ( display, main_window, &attr ) == 0 ) {
main_window = __create_window ( display ); main_window = __create_window ( display, menu_flags );
if ( sncontext != NULL ) { if ( sncontext != NULL ) {
sn_launchee_context_setup_window ( sncontext, main_window ); sn_launchee_context_setup_window ( sncontext, main_window );
} }
@ -1633,7 +1643,7 @@ void rofi_view_error_dialog ( const char *msg, int markup )
// main window isn't explicitly destroyed in case we switch modes. Reusing it prevents flicker // main window isn't explicitly destroyed in case we switch modes. Reusing it prevents flicker
XWindowAttributes attr; XWindowAttributes attr;
if ( main_window == None || XGetWindowAttributes ( display, main_window, &attr ) == 0 ) { if ( main_window == None || XGetWindowAttributes ( display, main_window, &attr ) == 0 ) {
main_window = __create_window ( display ); main_window = __create_window ( display, MENU_NORMAL );
} }
rofi_view_calculate_window_and_element_width ( state, &( state->mon ) ); rofi_view_calculate_window_and_element_width ( state, &( state->mon ) );
@ -1692,3 +1702,33 @@ void rofi_view_cleanup ()
map = None; map = None;
} }
} }
void rofi_view_workers_initialize ( void )
{
TICK_N ( "Setup Threadpool, start" );
// Create thread pool
GError *error = NULL;
tpool = g_thread_pool_new ( rofi_view_call_thread, NULL, config.threads, FALSE, &error );
if ( error == NULL ) {
// Idle threads should stick around for a max of 60 seconds.
g_thread_pool_set_max_idle_time ( 60000 );
// We are allowed to have
g_thread_pool_set_max_threads ( tpool, config.threads, &error );
}
// If error occured during setup of pool, tell user and exit.
if ( error != NULL ) {
char *msg = g_strdup_printf ( "Failed to setup thread pool: '%s'", error->message );
show_error_message ( msg, FALSE );
g_free ( msg );
g_error_free ( error );
exit ( EXIT_FAILURE );
}
TICK_N ( "Setup Threadpool, done" );
}
void rofi_view_workers_finalize ( void )
{
if ( tpool ) {
g_thread_pool_free ( tpool, TRUE, FALSE );
tpool = NULL;
}
}

View File

@ -328,12 +328,8 @@ int window_send_message ( Display *display, Window trg, Window subject, Atom ato
return r; return r;
} }
extern unsigned int normal_window_mode;
int take_keyboard ( Display *display, Window w ) int take_keyboard ( Display *display, Window w )
{ {
if ( normal_window_mode ) {
return 1;
}
for ( int i = 0; i < 500; i++ ) { for ( int i = 0; i < 500; i++ ) {
if ( XGrabKeyboard ( display, w, True, GrabModeAsync, GrabModeAsync, if ( XGrabKeyboard ( display, w, True, GrabModeAsync, GrabModeAsync,
CurrentTime ) == GrabSuccess ) { CurrentTime ) == GrabSuccess ) {
@ -347,9 +343,7 @@ int take_keyboard ( Display *display, Window w )
void release_keyboard ( Display *display ) void release_keyboard ( Display *display )
{ {
if ( !normal_window_mode ) { XUngrabKeyboard ( display, CurrentTime );
XUngrabKeyboard ( display, CurrentTime );
}
} }
// bind a key combination on a root window, compensating for Lock* states // bind a key combination on a root window, compensating for Lock* states
void x11_grab_key ( Display *display, unsigned int modmask, KeySym key ) void x11_grab_key ( Display *display, unsigned int modmask, KeySym key )