summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorQC <qball@gmpclient.org>2015-10-18 13:40:39 +0200
committerQC <qball@gmpclient.org>2015-10-18 13:40:39 +0200
commit93b6b83fb9fc1add7ebc781c7df20e005352acfb (patch)
tree45cf356b59653c2894e86974246a93df50f2ca79 /source
parentb1883ccaea53c79c6bbcf636b0e50a3b266b03bb (diff)
Try todo some validation of monitor size/padding in config sanity check.
Diffstat (limited to 'source')
-rw-r--r--source/helper.c31
-rw-r--r--source/keyb.c2
-rw-r--r--source/rofi.c13
-rw-r--r--source/x11-helper.c19
4 files changed, 60 insertions, 5 deletions
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 ) );