1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-03-10 17:06:37 -04:00

Full mainloop madness

This commit is contained in:
Dave Davenport 2016-02-19 19:50:48 +01:00
parent 4eb3fd1da3
commit 6e3bb506de
6 changed files with 37 additions and 39 deletions

View file

@ -137,7 +137,7 @@ void remove_pid_file ( int fd );
* *
* This functions exits the program with 1 when it finds an invalid configuration. * This functions exits the program with 1 when it finds an invalid configuration.
*/ */
void config_sanity_check ( Display *display ); int config_sanity_check ( Display *display );
/** /**
* @param arg string to parse. * @param arg string to parse.

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

@ -406,7 +406,6 @@ static void dmenu_finalize ( RofiViewState *state )
rofi_view_free ( state ); rofi_view_free ( state );
mode_destroy ( &dmenu_mode ); mode_destroy ( &dmenu_mode );
rofi_view_set_active ( NULL ); rofi_view_set_active ( NULL );
// g_main_loop_quit(NULL);
return; return;
} }
pd->selected_line = next_pos - 1; pd->selected_line = next_pos - 1;

View file

@ -508,7 +508,7 @@ void remove_pid_file ( int fd )
* *
* This functions exits the program with 1 when it finds an invalid configuration. * This functions exits the program with 1 when it finds an invalid configuration.
*/ */
void config_sanity_check ( Display *display ) int config_sanity_check ( Display *display )
{ {
if ( config.threads == 0 ) { if ( config.threads == 0 ) {
config.threads = 1; config.threads = 1;
@ -591,10 +591,11 @@ void config_sanity_check ( Display *display )
if ( found_error ) { if ( found_error ) {
g_string_append ( msg, "Please update your configuration." ); g_string_append ( msg, "Please update your configuration." );
show_error_message ( msg->str, TRUE ); show_error_message ( msg->str, TRUE );
exit ( EXIT_FAILURE ); return TRUE;
} }
g_string_free ( msg, TRUE ); g_string_free ( msg, TRUE );
return FALSE;
} }
char *rofi_expand_path ( const char *input ) char *rofi_expand_path ( const char *input )

View file

@ -207,6 +207,7 @@ static void run_switcher ( ModeMode mode )
char *input = g_strdup ( config.filter ); char *input = g_strdup ( config.filter );
__run_switcher_internal ( mode, input ); __run_switcher_internal ( mode, input );
g_free ( input ); g_free ( input );
main_loop_x11_event_handler ( NULL );
} }
void process_result ( RofiViewState *state ) void process_result ( RofiViewState *state )
{ {
@ -247,7 +248,6 @@ void process_result ( RofiViewState *state )
*/ */
__run_switcher_internal ( mode, input ); __run_switcher_internal ( mode, input );
g_free ( input ); g_free ( input );
main_loop_x11_event_handler ( NULL );
return; return;
} }
// Cleanup // Cleanup
@ -655,18 +655,32 @@ static gboolean delayed_start ( G_GNUC_UNUSED gpointer data )
static gboolean startup ( G_GNUC_UNUSED gpointer data ) static gboolean startup ( G_GNUC_UNUSED gpointer data )
{ {
TICK_N ( "Startup" );
// flags to run immediately and exit // flags to run immediately and exit
char *sname = NULL; char *sname = NULL;
char *msg = NULL; char *msg = NULL;
//
// Sanity check
if ( config_sanity_check ( display ) ) {
return G_SOURCE_REMOVE;
}
TICK_N ( "Config sanity check" );
// Parse the keybindings.
parse_keys_abe ();
// Check if there is error dialog.
if ( rofi_view_get_active ( ) != NULL ) {
return G_SOURCE_REMOVE;
}
TICK_N ( "Parse ABE" );
// Dmenu mode. // Dmenu mode.
if ( dmenu_mode == TRUE ) { if ( dmenu_mode == TRUE ) {
// force off sidebar mode: // force off sidebar mode:
config.sidebar_mode = FALSE; config.sidebar_mode = FALSE;
int retv = run_dmenu (); int retv = run_dmenu ();
if ( retv ) { if ( retv ) {
rofi_set_return_code ( EXIT_SUCCESS ); rofi_set_return_code ( EXIT_SUCCESS );
// Directly exit. // Directly exit.
g_main_loop_quit(main_loop); g_main_loop_quit ( main_loop );
} }
} }
else if ( find_arg_str ( "-e", &( msg ) ) ) { else if ( find_arg_str ( "-e", &( msg ) ) ) {
@ -840,15 +854,6 @@ int main ( int argc, char *argv[] )
// Reload for dynamic part. // Reload for dynamic part.
load_configuration_dynamic ( display ); load_configuration_dynamic ( display );
} }
x11_setup ( display );
main_loop_source = x11_event_source_new ( display );
x11_event_source_set_callback ( main_loop_source, main_loop_x11_event_handler );
TICK_N ( "X11 Setup " );
// Sanity check
config_sanity_check ( display );
TICK_N ( "Config sanity check" );
// Dump. // Dump.
// catch help request // catch help request
if ( find_arg ( "-h" ) >= 0 || find_arg ( "-help" ) >= 0 || find_arg ( "--help" ) >= 0 ) { if ( find_arg ( "-h" ) >= 0 || find_arg ( "-help" ) >= 0 || find_arg ( "--help" ) >= 0 ) {
@ -863,9 +868,12 @@ int main ( int argc, char *argv[] )
config_parse_xresources_theme_dump (); config_parse_xresources_theme_dump ();
exit ( EXIT_SUCCESS ); exit ( EXIT_SUCCESS );
} }
// Parse the keybindings.
parse_keys_abe (); x11_setup ( display );
TICK_N ( "Parse ABE" ); main_loop_source = x11_event_source_new ( display );
x11_event_source_set_callback ( main_loop_source, main_loop_x11_event_handler );
TICK_N ( "X11 Setup " );
rofi_view_workers_initialize (); rofi_view_workers_initialize ();

View file

@ -1628,7 +1628,6 @@ RofiViewState *rofi_view_create ( Mode *sw,
} }
static void __error_dialog_event_loop ( RofiViewState *state, XEvent *ev ) static void __error_dialog_event_loop ( RofiViewState *state, XEvent *ev )
{ {
printf ( "Event\n" );
// Handle event. // Handle event.
if ( ev->type == Expose ) { if ( ev->type == Expose ) {
while ( XCheckTypedEvent ( display, Expose, ev ) ) { while ( XCheckTypedEvent ( display, Expose, ev ) ) {
@ -1689,7 +1688,6 @@ void rofi_view_error_dialog ( const char *msg, int markup )
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, MENU_NORMAL ); main_window = __create_window ( display, MENU_NORMAL );
printf ( "new window\n" );
} }
rofi_view_calculate_window_and_element_width ( state ); rofi_view_calculate_window_and_element_width ( state );
@ -1711,18 +1709,10 @@ void rofi_view_error_dialog ( const char *msg, int markup )
XMapRaised ( display, main_window ); XMapRaised ( display, main_window );
if ( sncontext != NULL ) { if ( sncontext != NULL ) {
// sn_launchee_context_complete ( sncontext ); sn_launchee_context_complete ( sncontext );
} }
printf ( "start\n" );
rofi_view_set_active ( state ); rofi_view_set_active ( state );
//rofi_view_queue_redraw();
main_loop_x11_event_handler ( NULL ); main_loop_x11_event_handler ( NULL );
//while ( !rofi_view_get_completed ( state ) ) {
// printf("main loop: %d\n", g_main_context_is_owner(g_main_context_default()));
// g_main_context_iteration ( NULL, TRUE );
//}
//rofi_view_set_active ( NULL );
//rofi_view_free ( state );
} }
void rofi_view_cleanup () void rofi_view_cleanup ()