mirror of
https://github.com/davatorium/rofi.git
synced 2025-03-03 16:05:20 -05:00
Cleanups.
This commit is contained in:
parent
63fd534ba2
commit
d9aef65ea7
5 changed files with 49 additions and 53 deletions
|
@ -36,6 +36,7 @@ typedef enum
|
|||
* @returns SwitcherMode
|
||||
*/
|
||||
typedef SwitcherMode ( *switcher_callback )( char **input, void *data );
|
||||
typedef void ( *switcher_callback_free_data )( void *data );
|
||||
|
||||
/**
|
||||
* State returned by the rofi window.
|
||||
|
|
|
@ -38,5 +38,5 @@ ScriptOptions *script_switcher_parse_setup ( const char *str );
|
|||
*
|
||||
* Free the ScriptOptions block.
|
||||
*/
|
||||
void script_switcher_free_options ( ScriptOptions *sw );
|
||||
void script_switcher_free_options ( void *data );
|
||||
#endif
|
||||
|
|
|
@ -380,7 +380,6 @@ void create_pid_file ( const char *pidfile )
|
|||
|
||||
void config_parse_cmd_options ( int argc, char ** argv )
|
||||
{
|
||||
|
||||
find_arg_str ( argc, argv, "-switchers", &( config.switchers ) );
|
||||
// Parse commandline arguments about the looks.
|
||||
find_arg_uint ( argc, argv, "-opacity", &( config.window_opacity ) );
|
||||
|
|
|
@ -109,6 +109,7 @@ typedef struct _Switcher
|
|||
switcher_callback cb;
|
||||
// Callback data.
|
||||
void *cb_data;
|
||||
switcher_callback_free_data cb_data_free;
|
||||
// Textbox used in the sidebar-mode.
|
||||
textbox *tb;
|
||||
} Switcher;
|
||||
|
@ -248,11 +249,13 @@ void winlist_empty ( winlist *l )
|
|||
*/
|
||||
void winlist_free ( winlist *l )
|
||||
{
|
||||
if ( l != NULL ) {
|
||||
winlist_empty ( l );
|
||||
g_free ( l->array );
|
||||
g_free ( l->data );
|
||||
g_free ( l );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param l The winlist.
|
||||
|
@ -2144,9 +2147,9 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
|
|||
display = XOpenDisplay ( display_str );
|
||||
XSync ( display, True );
|
||||
}
|
||||
// Create pid file
|
||||
// Create pid file to avoid multiple instances.
|
||||
create_pid_file ( pidfile );
|
||||
|
||||
// Create the colormap and the main visual.
|
||||
create_visual_and_colormap ();
|
||||
|
||||
// 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_hlbg,
|
||||
config.menu_hlfg );
|
||||
char *input = NULL;
|
||||
// Otherwise check if requested mode is enabled.
|
||||
if ( switchers[mode].cb != NULL ) {
|
||||
char *input = NULL;
|
||||
do {
|
||||
SwitcherMode retv;
|
||||
|
||||
|
@ -2185,8 +2188,8 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
|
|||
mode = retv;
|
||||
}
|
||||
} while ( mode != MODE_EXIT );
|
||||
}
|
||||
g_free ( input );
|
||||
}
|
||||
|
||||
// Cleanup font setup.
|
||||
textbox_cleanup ( );
|
||||
|
@ -2205,32 +2208,26 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
|
|||
*/
|
||||
static void handle_keypress ( XEvent *ev )
|
||||
{
|
||||
int index = -1;
|
||||
KeySym key = XkbKeycodeToKeysym ( display, ev->xkey.keycode, 0, 0 );
|
||||
|
||||
if ( ( windows_modmask == AnyModifier || ev->xkey.state & windows_modmask ) &&
|
||||
key == windows_keysym ) {
|
||||
int index = switcher_get ( "window" );
|
||||
if ( index >= 0 ) {
|
||||
run_switcher ( TRUE, index );
|
||||
}
|
||||
index = switcher_get ( "window" );
|
||||
}
|
||||
|
||||
if ( ( rundialog_modmask == AnyModifier || ev->xkey.state & rundialog_modmask ) &&
|
||||
key == rundialog_keysym ) {
|
||||
int index = switcher_get ( "run" );
|
||||
if ( index >= 0 ) {
|
||||
run_switcher ( TRUE, index );
|
||||
}
|
||||
index = switcher_get ( "run" );
|
||||
}
|
||||
|
||||
if ( ( sshdialog_modmask == AnyModifier || ev->xkey.state & sshdialog_modmask ) &&
|
||||
key == sshdialog_keysym ) {
|
||||
int index = switcher_get ( "ssh" );
|
||||
index = switcher_get ( "ssh" );
|
||||
}
|
||||
if ( index >= 0 ) {
|
||||
run_switcher ( TRUE, index );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// convert a Mod+key arg to mod mask and keysym
|
||||
static void parse_key ( char *combo, unsigned int *mod, KeySym *key )
|
||||
|
@ -2341,24 +2338,18 @@ static void cleanup ()
|
|||
XCloseDisplay ( display );
|
||||
}
|
||||
}
|
||||
if ( cache_xattr != NULL ) {
|
||||
winlist_free ( cache_xattr );
|
||||
}
|
||||
if ( cache_client != NULL ) {
|
||||
winlist_free ( cache_client );
|
||||
}
|
||||
|
||||
i3_support_free_internals ();
|
||||
|
||||
|
||||
// Cleaning up memory allocated by the Xresources file.
|
||||
// TODO, not happy with this.
|
||||
config_xresource_free ();
|
||||
|
||||
for ( unsigned int i = 0; i < num_switchers; i++ ) {
|
||||
// only used for script dialog.
|
||||
if ( switchers[i].cb_data != NULL ) {
|
||||
script_switcher_free_options ( switchers[i].cb_data );
|
||||
if ( switchers[i].cb_data_free != NULL ) {
|
||||
switchers[i].cb_data_free ( switchers[i].cb_data );
|
||||
}
|
||||
}
|
||||
g_free ( switchers );
|
||||
|
@ -2393,6 +2384,7 @@ static void setup_switchers ( void )
|
|||
g_strlcpy ( switchers[num_switchers].name, "window", 32 );
|
||||
switchers[num_switchers].cb = run_switcher_window;
|
||||
switchers[num_switchers].cb_data = NULL;
|
||||
switchers[num_switchers].cb_data_free = NULL;
|
||||
num_switchers++;
|
||||
}
|
||||
// SSh dialog
|
||||
|
@ -2402,6 +2394,7 @@ static void setup_switchers ( void )
|
|||
g_strlcpy ( switchers[num_switchers].name, "ssh", 32 );
|
||||
switchers[num_switchers].cb = ssh_switcher_dialog;
|
||||
switchers[num_switchers].cb_data = NULL;
|
||||
switchers[num_switchers].cb_data_free = NULL;
|
||||
num_switchers++;
|
||||
}
|
||||
// Run dialog
|
||||
|
@ -2411,6 +2404,7 @@ static void setup_switchers ( void )
|
|||
g_strlcpy ( switchers[num_switchers].name, "run", 32 );
|
||||
switchers[num_switchers].cb = run_switcher_dialog;
|
||||
switchers[num_switchers].cb_data = NULL;
|
||||
switchers[num_switchers].cb_data_free = NULL;
|
||||
num_switchers++;
|
||||
}
|
||||
else {
|
||||
|
@ -2422,6 +2416,7 @@ static void setup_switchers ( void )
|
|||
g_strlcpy ( switchers[num_switchers].name, sw->name, 32 );
|
||||
switchers[num_switchers].cb = script_switcher_dialog;
|
||||
switchers[num_switchers].cb_data = sw;
|
||||
switchers[num_switchers].cb_data_free = script_switcher_free_options;
|
||||
num_switchers++;
|
||||
}
|
||||
else{
|
||||
|
|
|
@ -131,8 +131,9 @@ SwitcherMode script_switcher_dialog ( char **input, void *data )
|
|||
return retv;
|
||||
}
|
||||
|
||||
void script_switcher_free_options ( ScriptOptions *sw )
|
||||
void script_switcher_free_options ( void *data )
|
||||
{
|
||||
ScriptOptions *sw = (ScriptOptions *) data;
|
||||
if ( sw == NULL ) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue