mirror of
https://github.com/davatorium/rofi.git
synced 2025-04-14 17:43:01 -04:00
Try todo some validation of monitor size/padding in config sanity check.
This commit is contained in:
parent
b1883ccaea
commit
93b6b83fb9
7 changed files with 69 additions and 6 deletions
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include <config.h>
|
||||
#include <string.h>
|
||||
#include "rofi.h"
|
||||
#include <X11/keysym.h>
|
||||
#include "x11-helper.h"
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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 ) );
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue