1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-03-03 16:05:20 -05:00

Cleanups.

This commit is contained in:
Dave Davenport 2015-02-04 09:37:34 +01:00
parent 63fd534ba2
commit d9aef65ea7
5 changed files with 49 additions and 53 deletions

View file

@ -36,6 +36,7 @@ typedef enum
* @returns SwitcherMode * @returns SwitcherMode
*/ */
typedef SwitcherMode ( *switcher_callback )( char **input, void *data ); typedef SwitcherMode ( *switcher_callback )( char **input, void *data );
typedef void ( *switcher_callback_free_data )( void *data );
/** /**
* State returned by the rofi window. * State returned by the rofi window.

View file

@ -38,5 +38,5 @@ ScriptOptions *script_switcher_parse_setup ( const char *str );
* *
* Free the ScriptOptions block. * Free the ScriptOptions block.
*/ */
void script_switcher_free_options ( ScriptOptions *sw ); void script_switcher_free_options ( void *data );
#endif #endif

View file

@ -380,7 +380,6 @@ void create_pid_file ( const char *pidfile )
void config_parse_cmd_options ( int argc, char ** argv ) void config_parse_cmd_options ( int argc, char ** argv )
{ {
find_arg_str ( argc, argv, "-switchers", &( config.switchers ) ); find_arg_str ( argc, argv, "-switchers", &( config.switchers ) );
// Parse commandline arguments about the looks. // Parse commandline arguments about the looks.
find_arg_uint ( argc, argv, "-opacity", &( config.window_opacity ) ); find_arg_uint ( argc, argv, "-opacity", &( config.window_opacity ) );

View file

@ -104,13 +104,14 @@ Atom netatoms[NUM_NETATOMS];
typedef struct _Switcher typedef struct _Switcher
{ {
// Name (max 31 char long) // Name (max 31 char long)
char name[32]; char name[32];
// Switcher callback. // Switcher callback.
switcher_callback cb; switcher_callback cb;
// Callback data. // Callback data.
void *cb_data; void *cb_data;
switcher_callback_free_data cb_data_free;
// Textbox used in the sidebar-mode. // Textbox used in the sidebar-mode.
textbox *tb; textbox *tb;
} Switcher; } Switcher;
// Array of switchers. // Array of switchers.
@ -248,10 +249,12 @@ void winlist_empty ( winlist *l )
*/ */
void winlist_free ( winlist *l ) void winlist_free ( winlist *l )
{ {
winlist_empty ( l ); if ( l != NULL ) {
g_free ( l->array ); winlist_empty ( l );
g_free ( l->data ); g_free ( l->array );
g_free ( l ); g_free ( l->data );
g_free ( l );
}
} }
/** /**
@ -2144,9 +2147,9 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
display = XOpenDisplay ( display_str ); display = XOpenDisplay ( display_str );
XSync ( display, True ); XSync ( display, True );
} }
// Create pid file // Create pid file to avoid multiple instances.
create_pid_file ( pidfile ); create_pid_file ( pidfile );
// Create the colormap and the main visual.
create_visual_and_colormap (); create_visual_and_colormap ();
// Because of the above fork, we want to do this here. // Because of the above fork, we want to do this here.
@ -2155,9 +2158,9 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
config.menu_bg, config.menu_bg_alt, config.menu_fg, config.menu_bg, config.menu_bg_alt, config.menu_fg,
config.menu_hlbg, config.menu_hlbg,
config.menu_hlfg ); config.menu_hlfg );
char *input = NULL;
// Otherwise check if requested mode is enabled. // Otherwise check if requested mode is enabled.
if ( switchers[mode].cb != NULL ) { if ( switchers[mode].cb != NULL ) {
char *input = NULL;
do { do {
SwitcherMode retv; SwitcherMode retv;
@ -2185,8 +2188,8 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
mode = retv; mode = retv;
} }
} while ( mode != MODE_EXIT ); } while ( mode != MODE_EXIT );
g_free ( input );
} }
g_free ( input );
// Cleanup font setup. // Cleanup font setup.
textbox_cleanup ( ); textbox_cleanup ( );
@ -2205,30 +2208,24 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
*/ */
static void handle_keypress ( XEvent *ev ) static void handle_keypress ( XEvent *ev )
{ {
KeySym key = XkbKeycodeToKeysym ( display, ev->xkey.keycode, 0, 0 ); int index = -1;
KeySym key = XkbKeycodeToKeysym ( display, ev->xkey.keycode, 0, 0 );
if ( ( windows_modmask == AnyModifier || ev->xkey.state & windows_modmask ) && if ( ( windows_modmask == AnyModifier || ev->xkey.state & windows_modmask ) &&
key == windows_keysym ) { key == windows_keysym ) {
int index = switcher_get ( "window" ); index = switcher_get ( "window" );
if ( index >= 0 ) {
run_switcher ( TRUE, index );
}
} }
if ( ( rundialog_modmask == AnyModifier || ev->xkey.state & rundialog_modmask ) && if ( ( rundialog_modmask == AnyModifier || ev->xkey.state & rundialog_modmask ) &&
key == rundialog_keysym ) { key == rundialog_keysym ) {
int index = switcher_get ( "run" ); index = switcher_get ( "run" );
if ( index >= 0 ) {
run_switcher ( TRUE, index );
}
} }
if ( ( sshdialog_modmask == AnyModifier || ev->xkey.state & sshdialog_modmask ) && if ( ( sshdialog_modmask == AnyModifier || ev->xkey.state & sshdialog_modmask ) &&
key == sshdialog_keysym ) { key == sshdialog_keysym ) {
int index = switcher_get ( "ssh" ); index = switcher_get ( "ssh" );
if ( index >= 0 ) { }
run_switcher ( TRUE, index ); if ( index >= 0 ) {
} run_switcher ( TRUE, index );
} }
} }
@ -2341,24 +2338,18 @@ static void cleanup ()
XCloseDisplay ( display ); XCloseDisplay ( display );
} }
} }
if ( cache_xattr != NULL ) { winlist_free ( cache_xattr );
winlist_free ( cache_xattr ); winlist_free ( cache_client );
}
if ( cache_client != NULL ) {
winlist_free ( cache_client );
}
i3_support_free_internals (); i3_support_free_internals ();
// Cleaning up memory allocated by the Xresources file. // Cleaning up memory allocated by the Xresources file.
// TODO, not happy with this.
config_xresource_free (); config_xresource_free ();
for ( unsigned int i = 0; i < num_switchers; i++ ) { for ( unsigned int i = 0; i < num_switchers; i++ ) {
// only used for script dialog. // only used for script dialog.
if ( switchers[i].cb_data != NULL ) { if ( switchers[i].cb_data_free != NULL ) {
script_switcher_free_options ( switchers[i].cb_data ); switchers[i].cb_data_free ( switchers[i].cb_data );
} }
} }
g_free ( switchers ); g_free ( switchers );
@ -2391,8 +2382,9 @@ static void setup_switchers ( void )
// Resize and add entry. // Resize and add entry.
switchers = (Switcher *) g_realloc ( switchers, sizeof ( Switcher ) * ( num_switchers + 1 ) ); switchers = (Switcher *) g_realloc ( switchers, sizeof ( Switcher ) * ( num_switchers + 1 ) );
g_strlcpy ( switchers[num_switchers].name, "window", 32 ); g_strlcpy ( switchers[num_switchers].name, "window", 32 );
switchers[num_switchers].cb = run_switcher_window; switchers[num_switchers].cb = run_switcher_window;
switchers[num_switchers].cb_data = NULL; switchers[num_switchers].cb_data = NULL;
switchers[num_switchers].cb_data_free = NULL;
num_switchers++; num_switchers++;
} }
// SSh dialog // SSh dialog
@ -2400,8 +2392,9 @@ static void setup_switchers ( void )
// Resize and add entry. // Resize and add entry.
switchers = (Switcher *) g_realloc ( switchers, sizeof ( Switcher ) * ( num_switchers + 1 ) ); switchers = (Switcher *) g_realloc ( switchers, sizeof ( Switcher ) * ( num_switchers + 1 ) );
g_strlcpy ( switchers[num_switchers].name, "ssh", 32 ); g_strlcpy ( switchers[num_switchers].name, "ssh", 32 );
switchers[num_switchers].cb = ssh_switcher_dialog; switchers[num_switchers].cb = ssh_switcher_dialog;
switchers[num_switchers].cb_data = NULL; switchers[num_switchers].cb_data = NULL;
switchers[num_switchers].cb_data_free = NULL;
num_switchers++; num_switchers++;
} }
// Run dialog // Run dialog
@ -2409,8 +2402,9 @@ static void setup_switchers ( void )
// Resize and add entry. // Resize and add entry.
switchers = (Switcher *) g_realloc ( switchers, sizeof ( Switcher ) * ( num_switchers + 1 ) ); switchers = (Switcher *) g_realloc ( switchers, sizeof ( Switcher ) * ( num_switchers + 1 ) );
g_strlcpy ( switchers[num_switchers].name, "run", 32 ); g_strlcpy ( switchers[num_switchers].name, "run", 32 );
switchers[num_switchers].cb = run_switcher_dialog; switchers[num_switchers].cb = run_switcher_dialog;
switchers[num_switchers].cb_data = NULL; switchers[num_switchers].cb_data = NULL;
switchers[num_switchers].cb_data_free = NULL;
num_switchers++; num_switchers++;
} }
else { else {
@ -2420,8 +2414,9 @@ static void setup_switchers ( void )
// Resize and add entry. // Resize and add entry.
switchers = (Switcher *) g_realloc ( switchers, sizeof ( Switcher ) * ( num_switchers + 1 ) ); switchers = (Switcher *) g_realloc ( switchers, sizeof ( Switcher ) * ( num_switchers + 1 ) );
g_strlcpy ( switchers[num_switchers].name, sw->name, 32 ); g_strlcpy ( switchers[num_switchers].name, sw->name, 32 );
switchers[num_switchers].cb = script_switcher_dialog; switchers[num_switchers].cb = script_switcher_dialog;
switchers[num_switchers].cb_data = sw; switchers[num_switchers].cb_data = sw;
switchers[num_switchers].cb_data_free = script_switcher_free_options;
num_switchers++; num_switchers++;
} }
else{ else{
@ -2477,7 +2472,7 @@ static void hup_action_handler ( int num )
} }
} }
static void show_error_message( const char *msg ) static void show_error_message ( const char *msg )
{ {
// Create pid file // Create pid file
create_pid_file ( pidfile ); create_pid_file ( pidfile );
@ -2485,9 +2480,9 @@ static void show_error_message( const char *msg )
// Request truecolor visual. // Request truecolor visual.
create_visual_and_colormap (); create_visual_and_colormap ();
textbox_setup ( &vinfo, map, textbox_setup ( &vinfo, map,
config.menu_bg, config.menu_bg_alt, config.menu_fg, config.menu_bg, config.menu_bg_alt, config.menu_fg,
config.menu_hlbg, config.menu_hlbg,
config.menu_hlfg ); config.menu_hlfg );
error_dialog ( msg ); error_dialog ( msg );
textbox_cleanup ( ); textbox_cleanup ( );
if ( map != None ) { if ( map != None ) {
@ -2518,7 +2513,7 @@ int main ( int argc, char *argv[] )
cache_dir = g_get_user_cache_dir (); cache_dir = g_get_user_cache_dir ();
// Create pid file path. // Create pid file path.
if( find_arg_str_alloc ( argc, argv, "-pid", &( pidfile ) ) == FALSE ) { if ( find_arg_str_alloc ( argc, argv, "-pid", &( pidfile ) ) == FALSE ) {
const char *path = g_get_user_runtime_dir (); const char *path = g_get_user_runtime_dir ();
if ( path ) { if ( path ) {
pidfile = g_build_filename ( path, "rofi.pid", NULL ); pidfile = g_build_filename ( path, "rofi.pid", NULL );
@ -2583,7 +2578,7 @@ int main ( int argc, char *argv[] )
char *msg = NULL; char *msg = NULL;
if ( find_arg_str ( argc, argv, "-e", &( msg ) ) ) { if ( find_arg_str ( argc, argv, "-e", &( msg ) ) ) {
show_error_message(msg); show_error_message ( msg );
exit ( EXIT_SUCCESS ); exit ( EXIT_SUCCESS );
} }

View file

@ -131,8 +131,9 @@ SwitcherMode script_switcher_dialog ( char **input, void *data )
return retv; return retv;
} }
void script_switcher_free_options ( ScriptOptions *sw ) void script_switcher_free_options ( void *data )
{ {
ScriptOptions *sw = (ScriptOptions *) data;
if ( sw == NULL ) { if ( sw == NULL ) {
return; return;
} }