mirror of https://github.com/davatorium/rofi.git
Extra checks, first part cleanup
This commit is contained in:
parent
6cd01dba0e
commit
0a95ba47fa
|
@ -24,6 +24,8 @@
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "rofi.h"
|
#include "rofi.h"
|
||||||
|
|
||||||
Settings config = {
|
Settings config = {
|
||||||
|
@ -33,14 +35,14 @@ Settings config = {
|
||||||
.window_opacity = 100,
|
.window_opacity = 100,
|
||||||
// Border width around the window.
|
// Border width around the window.
|
||||||
.menu_bw = 1,
|
.menu_bw = 1,
|
||||||
// The width of the switcher. (0-100 in % > 100 in pixels)
|
// The width of the switcher. (0100 in % > 100 in pixels)
|
||||||
.menu_width = 50,
|
.menu_width = 50,
|
||||||
// Maximum number of options to show.
|
// Maximum number of options to show.
|
||||||
.menu_lines = 15,
|
.menu_lines = 15,
|
||||||
// Number of columns
|
// Number of columns
|
||||||
.menu_columns = 1,
|
.menu_columns = 1,
|
||||||
// Font
|
// Font
|
||||||
.menu_font = "mono-12",
|
.menu_font = "mono12",
|
||||||
// Foreground color
|
// Foreground color
|
||||||
.menu_fg = "#222222",
|
.menu_fg = "#222222",
|
||||||
// Background color
|
// Background color
|
||||||
|
@ -74,3 +76,33 @@ Settings config = {
|
||||||
.x_offset = 0,
|
.x_offset = 0,
|
||||||
.fixed_num_lines = 0
|
.fixed_num_lines = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do some input validation, especially the first few could break things.
|
||||||
|
* It is good to catch them beforehand.
|
||||||
|
*
|
||||||
|
* This functions exits the program with 1 when it finds an invalid configuration.
|
||||||
|
*/
|
||||||
|
void config_sanity_check( void )
|
||||||
|
{
|
||||||
|
if ( config.menu_lines == 0 ) {
|
||||||
|
fprintf(stderr, "config.menu_lines is invalid. You need at least one visible line.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if ( config.menu_columns == 0 ) {
|
||||||
|
fprintf(stderr, "config.menu_columns is invalid. You need at least one visible column.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( config.menu_width == 0 ) {
|
||||||
|
fprintf(stderr, "config.menu_width is invalid. You cannot have a window with no width.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !( config.location >= WL_CENTER && config.location <= WL_WEST ) )
|
||||||
|
{
|
||||||
|
fprintf(stderr, "config.location is invalid. ( %d >= %d >= %d) does not hold.\n",
|
||||||
|
WL_WEST, config.location, WL_CENTER);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -107,4 +107,6 @@ extern Settings config;
|
||||||
int token_match ( char **tokens, const char *input,
|
int token_match ( char **tokens, const char *input,
|
||||||
__attribute__( ( unused ) ) int index,
|
__attribute__( ( unused ) ) int index,
|
||||||
__attribute__( ( unused ) ) void *data );
|
__attribute__( ( unused ) ) void *data );
|
||||||
|
|
||||||
|
void config_sanity_check ( void );
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -320,8 +320,8 @@ typedef struct
|
||||||
int len;
|
int len;
|
||||||
} winlist;
|
} winlist;
|
||||||
|
|
||||||
winlist *cache_client;
|
winlist *cache_client = NULL;
|
||||||
winlist *cache_xattr;
|
winlist *cache_xattr = NULL;
|
||||||
|
|
||||||
#define winlist_ascend( l, i, w ) for ( ( i ) = 0; ( i ) < ( l )->len && ( ( ( w ) = ( l )->array[i] ) || 1 ); ( i )++ )
|
#define winlist_ascend( l, i, w ) for ( ( i ) = 0; ( i ) < ( l )->len && ( ( ( w ) = ( l )->array[i] ) || 1 ); ( i )++ )
|
||||||
#define winlist_descend( l, i, w ) for ( ( i ) = ( l )->len - 1; ( i ) >= 0 && ( ( ( w ) = ( l )->array[i] ) || 1 ); ( i )-- )
|
#define winlist_descend( l, i, w ) for ( ( i ) = ( l )->len - 1; ( i ) >= 0 && ( ( ( w ) = ( l )->array[i] ) || 1 ); ( i )-- )
|
||||||
|
@ -1893,6 +1893,38 @@ static void parse_cmd_options( int argc, char ** argv )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cleanup()
|
||||||
|
{
|
||||||
|
printf("cleanup\n");
|
||||||
|
// Cleanup
|
||||||
|
if ( display != NULL )
|
||||||
|
{
|
||||||
|
if ( main_window != None )
|
||||||
|
{
|
||||||
|
XFreeGC ( display, gc );
|
||||||
|
XDestroyWindow ( display, main_window );
|
||||||
|
XCloseDisplay ( display );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(cache_xattr != NULL)
|
||||||
|
{
|
||||||
|
winlist_free ( cache_xattr );
|
||||||
|
}
|
||||||
|
if(cache_client != NULL)
|
||||||
|
{
|
||||||
|
winlist_free ( cache_client );
|
||||||
|
}
|
||||||
|
#ifdef HAVE_I3_IPC_H
|
||||||
|
|
||||||
|
if ( i3_socket_path != NULL )
|
||||||
|
{
|
||||||
|
free ( i3_socket_path );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
xdgWipeHandle ( &xdg_handle );
|
||||||
|
|
||||||
|
}
|
||||||
int main ( int argc, char *argv[] )
|
int main ( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
@ -1913,6 +1945,7 @@ int main ( int argc, char *argv[] )
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get DISPLAY
|
// Get DISPLAY
|
||||||
char *display_str = getenv ( "DISPLAY" );
|
char *display_str = getenv ( "DISPLAY" );
|
||||||
find_arg_str ( argc, argv, "-display", &display_str );
|
find_arg_str ( argc, argv, "-display", &display_str );
|
||||||
|
@ -1930,6 +1963,9 @@ int main ( int argc, char *argv[] )
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register cleanup function.
|
||||||
|
atexit(cleanup);
|
||||||
|
|
||||||
cache_dir = xdgCacheHome ( &xdg_handle );
|
cache_dir = xdgCacheHome ( &xdg_handle );
|
||||||
|
|
||||||
|
|
||||||
|
@ -1976,6 +2012,9 @@ int main ( int argc, char *argv[] )
|
||||||
// Parse command line for settings.
|
// Parse command line for settings.
|
||||||
parse_cmd_options ( argc, argv );
|
parse_cmd_options ( argc, argv );
|
||||||
|
|
||||||
|
// Sanity check
|
||||||
|
config_sanity_check ();
|
||||||
|
|
||||||
// flags to run immediately and exit
|
// flags to run immediately and exit
|
||||||
if ( find_arg ( argc, argv, "-now" ) >= 0 )
|
if ( find_arg ( argc, argv, "-now" ) >= 0 )
|
||||||
{
|
{
|
||||||
|
@ -2033,27 +2072,5 @@ int main ( int argc, char *argv[] )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
if ( display != NULL )
|
|
||||||
{
|
|
||||||
if ( main_window != None )
|
|
||||||
{
|
|
||||||
XFreeGC ( display, gc );
|
|
||||||
XDestroyWindow ( display, main_window );
|
|
||||||
XCloseDisplay ( display );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
winlist_free ( cache_xattr );
|
|
||||||
winlist_free ( cache_client );
|
|
||||||
#ifdef HAVE_I3_IPC_H
|
|
||||||
|
|
||||||
if ( i3_socket_path != NULL )
|
|
||||||
{
|
|
||||||
free ( i3_socket_path );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
xdgWipeHandle ( &xdg_handle );
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,7 @@ void parse_xresource_options ( Display *display )
|
||||||
{
|
{
|
||||||
if ( xrmOptions[i].type == xrm_String )
|
if ( xrmOptions[i].type == xrm_String )
|
||||||
{
|
{
|
||||||
|
//TODO this leaks memory.
|
||||||
*xrmOptions[i].str = ( char * ) malloc ( xrmValue.size * sizeof ( char ) );
|
*xrmOptions[i].str = ( char * ) malloc ( xrmValue.size * sizeof ( char ) );
|
||||||
strncpy ( *xrmOptions[i].str, xrmValue.addr, xrmValue.size );
|
strncpy ( *xrmOptions[i].str, xrmValue.addr, xrmValue.size );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue