diff options
-rw-r--r-- | include/helper.h | 2 | ||||
-rw-r--r-- | include/x11-helper.h | 1 | ||||
-rw-r--r-- | source/helper.c | 31 | ||||
-rw-r--r-- | source/keyb.c | 2 | ||||
-rw-r--r-- | source/rofi.c | 13 | ||||
-rw-r--r-- | source/x11-helper.c | 19 | ||||
-rw-r--r-- | test/helper-test.c | 7 |
7 files changed, 69 insertions, 6 deletions
diff --git a/include/helper.h b/include/helper.h index d75bfe35..01d42d4b 100644 --- a/include/helper.h +++ b/include/helper.h @@ -134,7 +134,7 @@ void remove_pid_file ( int fd ); * * This functions exits the program with 1 when it finds an invalid configuration. */ -void config_sanity_check ( void ); +void config_sanity_check ( Display *display ); /** * @param arg string to parse. diff --git a/include/x11-helper.h b/include/x11-helper.h index 1f688895..3c36328c 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -71,6 +71,7 @@ int window_send_message ( Display *display, Window target, Window subject, void monitor_dimensions ( Display *display, Screen *screen, int x, int y, workarea *mon ); // Find the dimensions of the monitor specified by user. int monitor_get_dimension ( Display *display, Screen *screen, int monitor, workarea *mon ); +int monitor_get_smallest_size ( Display *display ); /** * @param display The display. diff --git a/source/helper.c b/source/helper.c index 46491560..2d6956f1 100644 --- a/source/helper.c +++ b/source/helper.c @@ -39,6 +39,7 @@ #include <sys/stat.h> #include <ctype.h> #include "helper.h" +#include "x11-helper.h" #include "rofi.h" static int stored_argc = 0; @@ -536,7 +537,7 @@ void remove_pid_file ( int fd ) * * This functions exits the program with 1 when it finds an invalid configuration. */ -void config_sanity_check ( ) +void config_sanity_check ( Display *display ) { int found_error = FALSE; GString *msg = g_string_new ( @@ -554,7 +555,7 @@ void config_sanity_check ( ) found_error = TRUE; } if ( config.menu_width == 0 ) { - show_error_message ( "<b>config.menu_width</b>=0 is invalid. You cannot have a window with no width.", TRUE ); + g_string_append_printf ( msg, "<b>config.menu_width</b>=0 is invalid. You cannot have a window with no width." ); config.menu_columns = 50; found_error = TRUE; } @@ -572,9 +573,35 @@ void config_sanity_check ( ) found_error = 1; } } + + // Check size + { + int ssize = monitor_get_smallest_size ( display ); + if ( config.monitor >= 0 ) { + workarea mon; + if ( monitor_get_dimension ( display, DefaultScreenOfDisplay ( display ), config.monitor, &mon ) ) { + ssize = MIN ( mon.w, mon.h ); + } + else{ + g_string_append_printf ( msg, "\t<b>config.monitor</b>=%d Could not find monitor.\n", config.monitor ); + ssize = 0; + } + } + // Have todo an estimate here. + if ( ( 2 * ( config.padding + config.menu_bw ) ) > ( 0.9 * ssize ) ) { + g_string_append_printf ( msg, "\t<b>config.padding+config.menu_bw</b>=%d is to big for the minimum size of the monitor: %d.\n", + ( config.padding + config.menu_bw ), ssize ); + + config.padding = 0; + config.menu_bw = 0; + found_error = TRUE; + } + } + if ( found_error ) { g_string_append ( msg, "Please update your configuration." ); show_error_message ( msg->str, TRUE ); + exit ( EXIT_FAILURE ); } g_string_free ( msg, TRUE ); diff --git a/source/keyb.c b/source/keyb.c index 0f7e807e..4d8b4166 100644 --- a/source/keyb.c +++ b/source/keyb.c @@ -1,3 +1,5 @@ +#include <config.h> +#include <string.h> #include "rofi.h" #include <X11/keysym.h> #include "x11-helper.h" diff --git a/source/rofi.c b/source/rofi.c index 6256c7cf..abc8a263 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -948,10 +948,17 @@ 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 - config.padding ); + int h = ( state->h - state->top_offset - config.padding ); if ( config.sidebar_mode == TRUE ) { h -= state->line_height + config.line_margin; } + if ( h < 0 ) { + fprintf ( stderr, "Current padding %d (on each side) does not fit within visible window %d.\n", config.padding, state->h ); + h = ( state->h - state->top_offset - state->h / 3 ); + if ( config.sidebar_mode == TRUE ) { + h -= state->line_height + config.line_margin; + } + } state->max_rows = MAX ( 1, ( h / element_height ) ); state->max_elements = state->max_rows * config.menu_columns; // Free boxes no longer needed. @@ -1828,7 +1835,7 @@ static void reload_configuration () load_configuration_dynamic ( temp_display ); // Sanity check - config_sanity_check ( ); + config_sanity_check ( temp_display ); parse_keys_abe (); XCloseDisplay ( temp_display ); } @@ -2076,7 +2083,7 @@ int main ( int argc, char *argv[] ) x11_setup ( display ); // Sanity check - config_sanity_check ( ); + config_sanity_check ( display ); // Dump. // catch help request if ( find_arg ( "-h" ) >= 0 || find_arg ( "-help" ) >= 0 || find_arg ( "--help" ) >= 0 ) { diff --git a/source/x11-helper.c b/source/x11-helper.c index 346bb7ad..68bfe3a8 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -143,7 +143,26 @@ int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned l Atom type; int items; return window_get_prop ( display, w, atom, &type, &items, list, count * sizeof ( unsigned long ) ) && type == XA_CARDINAL ? items : 0; } +int monitor_get_smallest_size ( Display *display ) +{ + int size = MIN ( WidthOfScreen ( DefaultScreenOfDisplay ( display ) ), + HeightOfScreen ( DefaultScreenOfDisplay ( display ) ) ); + // locate the current monitor + if ( XineramaIsActive ( display ) ) { + int monitors; + XineramaScreenInfo *info = XineramaQueryScreens ( display, &monitors ); + if ( info ) { + for ( int i = 0; i < monitors; i++ ) { + size = MIN ( info[i].width, size ); + size = MIN ( info[i].height, size ); + } + } + XFree ( info ); + } + + return size; +} int monitor_get_dimension ( Display *display, Screen *screen, int monitor, workarea *mon ) { memset ( mon, 0, sizeof ( workarea ) ); diff --git a/test/helper-test.c b/test/helper-test.c index 6a1e865b..b12969db 100644 --- a/test/helper-test.c +++ b/test/helper-test.c @@ -21,6 +21,13 @@ int show_error_message ( const char *msg, int markup ) error_dialog ( msg, markup ); return 0; } +#include <x11-helper.h> +int monitor_get_smallest_size ( Display *d ) +{ +} +int monitor_get_dimension ( Display *d, Screen *screen, int monitor, workarea *mon ) +{ +} int main ( int argc, char ** argv ) { |