diff options
Diffstat (limited to 'source/view.c')
-rw-r--r-- | source/view.c | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/source/view.c b/source/view.c index 4abcafc5..9c51fbfe 100644 --- a/source/view.c +++ b/source/view.c @@ -400,6 +400,7 @@ static Window __create_window ( Display *display, MenuFlags menu_flags ) surface = cairo_xlib_surface_create ( display, box, vinfo.visual, 200, 100 ); // Create a drawable. draw = cairo_create ( surface ); + g_assert ( draw != NULL ); cairo_set_operator ( draw, CAIRO_OPERATOR_SOURCE ); // Set up pango context. @@ -690,14 +691,14 @@ static unsigned int rofi_scroll_per_page ( RofiViewState * state ) static unsigned int rofi_scroll_continious ( RofiViewState * state ) { - unsigned int middle = (state->menu_lines - ((state->menu_lines&1) == 0))/ 2; + unsigned int middle = ( state->menu_lines - ( ( state->menu_lines & 1 ) == 0 ) ) / 2; unsigned int offset = 0; if ( state->selected > middle ) { - if ( state->selected < ( state->filtered_lines - (state->menu_lines -middle) ) ) { + if ( state->selected < ( state->filtered_lines - ( state->menu_lines - middle ) ) ) { offset = state->selected - middle; } // Don't go below zero. - else if ( state->filtered_lines > state->menu_lines){ + else if ( state->filtered_lines > state->menu_lines ) { offset = state->filtered_lines - state->menu_lines; } } @@ -738,13 +739,13 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) element_width = ( element_width - ( columns - 1 ) * config.line_margin ) / columns; } - int element_height = state->line_height * config.element_height; - int y_offset = state->top_offset; - int x_offset = state->border; + int element_height = state->line_height * config.element_height; + int y_offset = state->top_offset; + int x_offset = state->border; if ( state->rchanged ) { // Move, resize visible boxes and show them. - for ( i = 0; i < max_elements && (i+offset) < state->filtered_lines; i++ ) { + for ( i = 0; i < max_elements && ( i + offset ) < state->filtered_lines; i++ ) { unsigned int ex = ( ( i ) / state->max_rows ) * ( element_width + config.line_margin ); unsigned int ey = ( ( i ) % state->max_rows ) * ( element_height + config.line_margin ); // Move it around. @@ -764,7 +765,7 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) } else{ // Only do basic redrawing + highlight of row. - for ( i = 0; i < max_elements && (i+offset) < state->filtered_lines; i++ ) { + for ( i = 0; i < max_elements && ( i + offset ) < state->filtered_lines; i++ ) { TextBoxFontType type = ( ( ( i % state->max_rows ) & 1 ) == 0 ) ? NORMAL : ALT; int fstate = 0; mode_get_display_value ( state->sw, state->line_map[i + offset], &fstate, FALSE ); @@ -1416,7 +1417,8 @@ RofiViewState *rofi_view_create ( Mode *sw, const char *input, char *prompt, const char *message, - MenuFlags menu_flags ) + MenuFlags menu_flags, + void ( *finalize )( RofiViewState *state ) ) { TICK (); RofiViewState *state = __rofi_view_state_create (); @@ -1434,6 +1436,7 @@ RofiViewState *rofi_view_create ( Mode *sw, state->cur_page = -1; state->border = config.padding + config.menu_bw; state->x11_event_loop = rofi_view_mainloop_iter; + state->finalize = finalize; // Request the lines to show. state->num_lines = mode_get_num_entries ( sw ); @@ -1625,6 +1628,7 @@ RofiViewState *rofi_view_create ( Mode *sw, } static void __error_dialog_event_loop ( RofiViewState *state, XEvent *ev ) { + printf ( "Event\n" ); // Handle event. if ( ev->type == Expose ) { while ( XCheckTypedEvent ( display, Expose, ev ) ) { @@ -1632,6 +1636,21 @@ static void __error_dialog_event_loop ( RofiViewState *state, XEvent *ev ) } state->update = TRUE; } + else if ( ev->type == ConfigureNotify ) { + XConfigureEvent xce = ev->xconfigure; + if ( xce.window == main_window ) { + if ( state->x != (int ) xce.x || state->y != (int) xce.y ) { + state->x = xce.x; + state->y = xce.y; + state->update = TRUE; + } + if ( state->w != (unsigned int) xce.width || state->h != (unsigned int ) xce.height ) { + state->w = xce.width; + state->h = xce.height; + cairo_xlib_surface_set_size ( surface, state->w, state->h ); + } + } + } // Key press event. else if ( ev->type == KeyPress ) { while ( XCheckTypedEvent ( display, KeyPress, ev ) ) { @@ -1641,6 +1660,7 @@ static void __error_dialog_event_loop ( RofiViewState *state, XEvent *ev ) } rofi_view_update ( state ); } +void process_result_error ( RofiViewState *state ); void rofi_view_error_dialog ( const char *msg, int markup ) { RofiViewState *state = __rofi_view_state_create (); @@ -1648,7 +1668,8 @@ void rofi_view_error_dialog ( const char *msg, int markup ) state->update = TRUE; state->border = config.padding + config.menu_bw; state->x11_event_loop = __error_dialog_event_loop; - state->finalize = NULL; + // TODO fix + state->finalize = process_result_error; // Try to grab the keyboard as early as possible. // We grab this using the rootwindow (as dmenu does it). @@ -1668,6 +1689,7 @@ void rofi_view_error_dialog ( const char *msg, int markup ) XWindowAttributes attr; if ( main_window == None || XGetWindowAttributes ( display, main_window, &attr ) == 0 ) { main_window = __create_window ( display, MENU_NORMAL ); + printf ( "new window\n" ); } rofi_view_calculate_window_and_element_width ( state ); @@ -1689,15 +1711,18 @@ void rofi_view_error_dialog ( const char *msg, int markup ) XMapRaised ( display, main_window ); if ( sncontext != NULL ) { - sn_launchee_context_complete ( sncontext ); +// sn_launchee_context_complete ( sncontext ); } + printf ( "start\n" ); rofi_view_set_active ( state ); + //rofi_view_queue_redraw(); main_loop_x11_event_handler ( NULL ); - while ( !rofi_view_get_completed ( state ) ) { - g_main_context_iteration ( NULL, TRUE ); - } - rofi_view_set_active ( NULL ); - rofi_view_free ( state ); + //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 () @@ -1756,4 +1781,8 @@ void rofi_view_workers_finalize ( void ) tpool = NULL; } } +Mode * rofi_view_get_mode ( RofiViewState *state ) +{ + return state->sw; +} |