From 0818fbd68b3f83941d15817f27f01b65c110c1fd Mon Sep 17 00:00:00 2001 From: QC Date: Fri, 16 Oct 2015 20:51:37 +0200 Subject: [PATCH] Add fullscreen mode and fix some redrawing issues. --- config/config.def.c | 1 + include/rofi.h | 2 ++ include/x11-helper.h | 1 + source/rofi.c | 41 ++++++++++++++++++++++++++--------------- source/textbox.c | 1 + source/xrmoptions.c | 3 ++- 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/config/config.def.c b/config/config.def.c index e971737d..fcf2f4cb 100644 --- a/config/config.def.c +++ b/config/config.def.c @@ -143,4 +143,5 @@ Settings config = { /** Hide scrollbar */ .hide_scrollbar = FALSE, .markup_rows = FALSE, + .fullscreen = FALSE, }; diff --git a/include/rofi.h b/include/rofi.h index d83c2d78..871a676c 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -244,6 +244,8 @@ typedef struct _Settings unsigned int hide_scrollbar; /** show markup in elements. */ unsigned int markup_rows; + /** fullscreen */ + unsigned int fullscreen; } Settings; /** Global Settings structure. */ diff --git a/include/x11-helper.h b/include/x11-helper.h index 588a0196..1f688895 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -45,6 +45,7 @@ int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned l X ( _NET_WM_WINDOW_TYPE_DOCK ), \ X ( _NET_WM_WINDOW_TYPE_DESKTOP ), \ X ( _NET_WM_WINDOW_TYPE_NORMAL ), \ + X ( _NET_WM_STATE_FULLSCREEN ), \ X ( _NET_WM_DESKTOP ), \ X ( CLIPBOARD ), \ X ( UTF8_STRING ), \ diff --git a/source/rofi.c b/source/rofi.c index 7e80b4af..6256c7cf 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -247,7 +247,7 @@ static Window create_window ( Display *display ) cairo_set_operator ( draw, CAIRO_OPERATOR_SOURCE ); // // make it an unmanaged window - if ( !normal_window_mode ) { + if ( !normal_window_mode && !config.fullscreen ) { window_set_atom_prop ( display, box, netatoms[_NET_WM_STATE], &netatoms[_NET_WM_STATE_ABOVE], 1 ); XSetWindowAttributes sattr = { .override_redirect = True }; XChangeWindowAttributes ( display, box, CWOverrideRedirect, &sattr ); @@ -255,6 +255,13 @@ static Window create_window ( Display *display ) else{ window_set_atom_prop ( display, box, netatoms[_NET_WM_WINDOW_TYPE], &netatoms[_NET_WM_WINDOW_TYPE_NORMAL], 1 ); } + if ( config.fullscreen ) { + Atom atoms[] = { + netatoms[_NET_WM_STATE_FULLSCREEN], + netatoms[_NET_WM_STATE_ABOVE] + }; + window_set_atom_prop ( display, box, netatoms[_NET_WM_STATE], atoms, sizeof ( atoms ) / sizeof ( Atom ) ); + } xim = XOpenIM ( display, NULL, NULL, NULL ); xic = XCreateIC ( xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, @@ -856,18 +863,18 @@ static void menu_update ( MenuState *state ) const double dashes[1] = { 4 }; cairo_set_dash ( d, dashes, 1, 0.0 ); } - cairo_move_to ( d, config.menu_bw, state->line_height + ( state->border ) * 1 + config.line_margin + 1 ); - cairo_line_to ( d, state->w - config.menu_bw, state->line_height + ( state->border ) * 1 + config.line_margin + 1 ); + cairo_move_to ( d, state->border, state->line_height + ( state->border ) * 1 + config.line_margin + 1 ); + cairo_line_to ( d, state->w - state->border, state->line_height + ( state->border ) * 1 + config.line_margin + 1 ); cairo_stroke ( d ); if ( state->message_tb ) { - cairo_move_to ( d, config.menu_bw, state->top_offset - ( config.line_margin ) - 1 ); - cairo_line_to ( d, state->w - config.menu_bw, state->top_offset - ( config.line_margin ) - 1 ); + cairo_move_to ( d, state->border, state->top_offset - ( config.line_margin ) - 1 ); + cairo_line_to ( d, state->w - state->border, state->top_offset - ( config.line_margin ) - 1 ); cairo_stroke ( d ); } if ( config.sidebar_mode == TRUE ) { - cairo_move_to ( d, config.menu_bw, state->h - state->line_height - ( state->border ) * 1 - 1 - config.line_margin ); - cairo_line_to ( d, state->w - config.menu_bw, state->h - state->line_height - ( state->border ) * 1 - 1 - config.line_margin ); + cairo_move_to ( d, state->border, state->h - state->line_height - ( state->border ) * 1 - 1 - config.line_margin ); + cairo_line_to ( d, state->w - state->border, state->h - state->line_height - ( state->border ) * 1 - 1 - config.line_margin ); cairo_stroke ( d ); } } @@ -924,11 +931,16 @@ static void menu_resize ( MenuState *state ) if ( config.sidebar_mode == TRUE ) { int width = ( state->w - ( 2 * ( state->border ) + ( num_switchers - 1 ) * config.line_margin ) ) / num_switchers; for ( unsigned int j = 0; j < num_switchers; j++ ) { - textbox_moveresize ( switchers[j].tb, state->border + j * ( width + config.line_margin ), - state->h - state->line_height - state->border, width, state->line_height ); + textbox_moveresize ( switchers[j].tb, + state->border + j * ( width + config.line_margin ), state->h - state->line_height - state->border, + width, state->line_height ); textbox_draw ( switchers[j].tb, draw ); } } + int entrybox_width = state->w - ( 2 * ( state->border ) ) - textbox_get_width ( state->prompt_tb ) + - textbox_get_width ( state->case_indicator ); + textbox_moveresize ( state->text, state->text->x, state->text->y, entrybox_width, state->line_height ); + textbox_move ( state->case_indicator, state->w - state->border - textbox_get_width ( state->case_indicator ), state->border ); /** * Resize in Height */ @@ -936,11 +948,11 @@ static void menu_resize ( MenuState *state ) unsigned int last_length = state->max_elements; int element_height = state->line_height * config.element_height + config.line_margin; // Calculated new number of boxes. - unsigned int h = ( state->h - state->top_offset ); + unsigned int h = ( state->h - state->top_offset - config.padding ); if ( config.sidebar_mode == TRUE ) { - h -= state->line_height + state->border; + h -= state->line_height + config.line_margin; } - state->max_rows = ( h / element_height ); + state->max_rows = MAX ( 1, ( h / element_height ) ); state->max_elements = state->max_rows * config.menu_columns; // Free boxes no longer needed. for ( unsigned int i = state->max_elements; i < last_length; i++ ) { @@ -1049,7 +1061,6 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select // Entry box int entrybox_width = state.w - ( 2 * ( state.border ) ) - textbox_get_width ( state.prompt_tb ) - textbox_get_width ( state.case_indicator ); - state.text = textbox_create ( TB_EDITABLE, ( state.border ) + textbox_get_width ( state.prompt_tb ), ( state.border ), entrybox_width, state.line_height, NORMAL, *input ); @@ -1063,7 +1074,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select textbox_text ( state.case_indicator, "*" ); } else{ - textbox_text ( state.case_indicator, "" ); + textbox_text ( state.case_indicator, " " ); } state.message_tb = NULL; if ( message ) { @@ -1277,7 +1288,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select textbox_text ( state.case_indicator, "*" ); } else { - textbox_text ( state.case_indicator, "" ); + textbox_text ( state.case_indicator, " " ); } } // Special delete entry command. diff --git a/source/textbox.c b/source/textbox.c index 15ce45a6..31c9b48e 100644 --- a/source/textbox.c +++ b/source/textbox.c @@ -191,6 +191,7 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ) // We always want to update this pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tb->w - 2 * SIDE_MARGIN ) ); + tb->update = TRUE; } // will also unmap the window if still displayed diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 16cac057..2e090215 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -132,7 +132,8 @@ static XrmOption xrmOptions[] = { { xrm_String, "filter", { .str = &config.filter }, NULL, "Pre-set the filter" }, { xrm_String, "separator-style", { .str = &config.separator_style }, NULL, "Separator style (none, dash, solid)" }, { xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL, "Hide the scroll-bar" }, - { xrm_Boolean, "markup-rows", { .num = &config.markup_rows }, NULL, "Show markup" } + { xrm_Boolean, "markup-rows", { .num = &config.markup_rows }, NULL, "Show markup" }, + { xrm_Boolean, "fullscreen", { .num = &config.fullscreen }, NULL, "Fullscreen" } }; // Dynamic options.