More splitting and abstracting.

This commit is contained in:
Dave Davenport 2016-01-07 21:27:20 +01:00
parent e8daff0f6a
commit fa51aeb484
14 changed files with 447 additions and 287 deletions

View File

@ -1,11 +1,11 @@
#ifndef ROFI_MODE_PRIVATE_H
#define ROFI_MODE_PRIVATE_H
typedef void ( *switcher_free )( Mode *data );
typedef void ( *_mode_free )( Mode *data );
typedef char * ( *switcher_get_display_value )( const Mode *sw, unsigned int selected_line, int *state, int get_entry );
typedef char * ( *_mode_get_display_value )( const Mode *sw, unsigned int selected_line, int *state, int get_entry );
typedef char * ( *switcher_get_completion )( const Mode *sw, unsigned int selected_line );
typedef char * ( *_mode_get_completion )( const Mode *sw, unsigned int selected_line );
/**
* @param tokens List of (input) tokens to match.
* @param input The entry to match against.
@ -17,7 +17,7 @@ typedef char * ( *switcher_get_completion )( const Mode *sw, unsigned int select
*
* @returns 1 when it matches, 0 if not.
*/
typedef int ( *switcher_token_match )( const Mode *data, char **tokens, int not_ascii, int case_sensitive, unsigned int index );
typedef int ( *_mode_token_match )( const Mode *data, char **tokens, int not_ascii, int case_sensitive, unsigned int index );
typedef void ( *__mode_init )( Mode *sw );
@ -25,9 +25,9 @@ typedef unsigned int ( *__mode_get_num_entries )( const Mode *sw );
typedef void ( *__mode_destroy )( Mode *sw );
typedef ModeMode ( *switcher_result )( Mode *sw, int menu_retv, char **input, unsigned int selected_line );
typedef ModeMode ( *_mode_result )( Mode *sw, int menu_retv, char **input, unsigned int selected_line );
typedef int ( *switcher_is_not_ascii )( const Mode *sw, unsigned int index );
typedef int ( *_mode_is_not_ascii )( const Mode *sw, unsigned int index );
/**
* Structure defining a switcher.
@ -48,32 +48,32 @@ struct _Mode
* A switcher normally consists of the following parts:
*/
/** Initialize the Mode */
__mode_init _init;
__mode_init _init;
/** Destroy the switcher, e.g. free all its memory. */
__mode_destroy _destroy;
__mode_destroy _destroy;
/** Get number of entries to display. (unfiltered). */
__mode_get_num_entries _get_num_entries;
__mode_get_num_entries _get_num_entries;
/** Check if the element is ascii. */
switcher_is_not_ascii is_not_ascii;
_mode_is_not_ascii _is_not_ascii;
/** Process the result of the user selection. */
switcher_result result;
_mode_result _result;
/** Token match. */
switcher_token_match token_match;
_mode_token_match _token_match;
/** Get the string to display for the entry. */
switcher_get_display_value mgrv;
_mode_get_display_value _get_display_value;
/** Get the 'completed' entry. */
switcher_get_completion get_completion;
_mode_get_completion _get_completion;
/** Pointer to private data. */
void *private_data;
void *private_data;
/**
* Free SWitcher
* Only to be used when the switcher object itself is dynamic.
* And has data in `ed`
*/
switcher_free free;
_mode_free free;
/** Extra fields for script */
void *ed;
void *ed;
};
#endif // ROFI_MODE_PRIVATE_H

View File

@ -83,5 +83,91 @@ unsigned int mode_get_num_entries ( const Mode *sw );
* @returns allocated new string and state when get_entry is TRUE otherwise just the state.
*/
char * mode_get_display_value ( const Mode *mode, unsigned int selected_line, int *state, int get_entry );
/**
* @param mode The mode to query
* @param selected_line The entry to query
*
* Return a string that can be used for completion. It has should have no markup.
*
* @returns allocated string.
*/
char * mode_get_completion ( const Mode *mode, unsigned int selected_line );
/**
* @param mode The mode to query
* @param selected_line The entry to query
*
* Check if the entry has non-ascii characters.
*
* @returns TRUE when selected line has non-ascii characters.
*/
int mode_is_not_ascii ( const Mode *mode, unsigned int selected_line );
/**
* @param mode Object The mode to query
* @param mretv The menu return value.
* @param input Pointer to the user input string.
* @param selected_line the line selected by the user.
*
* Acts on the user interaction.
*
* @returns the next #ModeMode.
*/
ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int selected_line );
/**
* @param mode Object The mode to query
* @param tokens The set of tokens to match against
* @param not_ascii If the entry is pure-ascii
* @param case_sensitive If the entry should be matched case sensitive
* @param selected_line The index of the entry to match
*
* Match entry against the set of tokens.
*
* @returns TRUE if matches
*/
int mode_token_match ( const Mode *mode, char **tokens, int not_ascii, int case_sensitive, unsigned int selected_line );
/**
* @param mode Object The mode to query
*
* Get the name of the mode.
*
* @returns the name of the mode.
*/
const char * mode_get_name ( const Mode *mode );
/**
* @param mode Object The mode to query
* @param key The KeySym to match
* @param state The Modmask to match
*
* Match keybinding of mode.
*
* return TRUE when matching, FALSE otherwise
*/
int mode_check_keybinding ( const Mode *mode, KeySym key, unsigned int modstate );
/**
* @param mode Object The mode to query
*
* Free the resources allocated for this mode.
*/
void mode_free ( Mode **mode );
/**
* @param mode Object The mode to query
*
* Setup the keybinding for this mode.
*/
void mode_setup_keybinding ( Mode *mode );
int mode_grab_key ( Mode *mode, Display *display );
void mode_ungrab_key ( Mode *mode, Display *display );
void mode_print_keybindings ( const Mode *mode );
void *mode_get_private_data ( const Mode *mode );
void mode_set_private_data ( Mode *mode, void *pd );
/*@}*/
#endif

View File

@ -39,14 +39,14 @@ typedef struct
typedef enum
{
TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21,
TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21,
} TextboxFlags;
typedef enum

View File

@ -32,7 +32,6 @@
#include <dialogs/dialogs.h>
#include "mode-private.h"
/**
* Combi Mode
*/
@ -50,7 +49,7 @@ typedef struct _CombiModePrivateData
static void combi_mode_parse_switchers ( Mode *sw )
{
CombiModePrivateData *pd = sw->private_data;
CombiModePrivateData *pd = mode_get_private_data ( sw );
char *savept = NULL;
// Make a copy, as strtok will modify it.
char *switcher_str = g_strdup ( config.combi_modi );
@ -102,9 +101,9 @@ static void combi_mode_parse_switchers ( Mode *sw )
static void combi_mode_init ( Mode *sw )
{
if ( sw->private_data == NULL ) {
if ( mode_get_private_data ( sw ) == NULL ) {
CombiModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
sw->private_data = (void *) pd;
mode_set_private_data ( sw, (void *) pd );
combi_mode_parse_switchers ( sw );
pd->starts = g_malloc0 ( sizeof ( int ) * pd->num_switchers );
pd->lengths = g_malloc0 ( sizeof ( int ) * pd->num_switchers );
@ -124,12 +123,12 @@ static void combi_mode_init ( Mode *sw )
}
static unsigned int combi_mode_get_num_entries ( const Mode *sw )
{
const CombiModePrivateData *pd = (const CombiModePrivateData *) sw->private_data;
const CombiModePrivateData *pd = (const CombiModePrivateData *) mode_get_private_data ( sw );
return pd->cmd_list_length;
}
static void combi_mode_destroy ( Mode *sw )
{
CombiModePrivateData *pd = (CombiModePrivateData *) sw->private_data;
CombiModePrivateData *pd = (CombiModePrivateData *) mode_get_private_data ( sw );
if ( pd != NULL ) {
g_free ( pd->starts );
g_free ( pd->lengths );
@ -139,16 +138,16 @@ static void combi_mode_destroy ( Mode *sw )
}
g_free ( pd->switchers );
g_free ( pd );
sw->private_data = NULL;
mode_set_private_data ( sw, NULL );
}
}
static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
{
CombiModePrivateData *pd = sw->private_data;
CombiModePrivateData *pd = mode_get_private_data ( sw );
if ( *input[0] == '!' ) {
int switcher = -1;
for ( unsigned i = 0; switcher == -1 && i < pd->num_switchers; i++ ) {
if ( ( *input )[1] == pd->switchers[i]->name[0] ) {
if ( ( *input )[1] == mode_get_name ( pd->switchers[i] )[0] ) {
switcher = i;
}
}
@ -157,8 +156,8 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned
// skip whitespace
if ( n != NULL ) {
n++;
return pd->switchers[switcher]->result ( pd->switchers[switcher], mretv, &n,
selected_line - pd->starts[switcher] );
return mode_result ( pd->switchers[switcher], mretv, &n,
selected_line - pd->starts[switcher] );
}
return MODE_EXIT;
}
@ -167,7 +166,7 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( selected_line >= pd->starts[i] &&
selected_line < ( pd->starts[i] + pd->lengths[i] ) ) {
return pd->switchers[i]->result ( pd->switchers[i], mretv, input, selected_line - pd->starts[i] );
return mode_result ( pd->switchers[i], mretv, input, selected_line - pd->starts[i] );
}
}
return MODE_EXIT;
@ -175,13 +174,13 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned
static int combi_mode_match ( const Mode *sw, char **tokens, int not_ascii,
int case_sensitive, unsigned int index )
{
CombiModePrivateData *pd = sw->private_data;
CombiModePrivateData *pd = mode_get_private_data ( sw );
if ( config.regex || config.glob ) {
// Bang support only works in text mode.
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
return pd->switchers[i]->token_match ( pd->switchers[i], tokens, not_ascii, case_sensitive,
index - pd->starts[i] );
return mode_token_match ( pd->switchers[i], tokens, not_ascii, case_sensitive,
index - pd->starts[i] );
}
}
}
@ -189,15 +188,15 @@ static int combi_mode_match ( const Mode *sw, char **tokens, int not_ascii,
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
if ( tokens && tokens[0][0] == '!' ) {
if ( tokens[0][1] == pd->switchers[i]->name[0] ) {
return pd->switchers[i]->token_match ( pd->switchers[i], &tokens[1], not_ascii, case_sensitive,
index - pd->starts[i] );
if ( tokens[0][1] == mode_get_name ( pd->switchers[i] )[0] ) {
return mode_token_match ( pd->switchers[i], &tokens[1], not_ascii, case_sensitive,
index - pd->starts[i] );
}
return 0;
}
else {
return pd->switchers[i]->token_match ( pd->switchers[i], tokens, not_ascii, case_sensitive,
index - pd->starts[i] );
return mode_token_match ( pd->switchers[i], tokens, not_ascii, case_sensitive,
index - pd->starts[i] );
}
}
}
@ -207,11 +206,11 @@ static int combi_mode_match ( const Mode *sw, char **tokens, int not_ascii,
}
static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *state, int get_entry )
{
CombiModePrivateData *pd = sw->private_data;
CombiModePrivateData *pd = mode_get_private_data ( sw );
if ( !get_entry ) {
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) {
pd->switchers[i]->mgrv ( pd->switchers[i], selected_line - pd->starts[i], state, FALSE );
mode_get_display_value ( pd->switchers[i], selected_line - pd->starts[i], state, FALSE );
return NULL;
}
}
@ -219,8 +218,8 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat
}
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) {
char * str = pd->switchers[i]->mgrv ( pd->switchers[i], selected_line - pd->starts[i], state, TRUE );
char * retv = g_strdup_printf ( "(%s) %s", pd->switchers[i]->name, str );
char * str = mode_get_display_value ( pd->switchers[i], selected_line - pd->starts[i], state, TRUE );
char * retv = g_strdup_printf ( "(%s) %s", mode_get_name ( pd->switchers[i] ), str );
g_free ( str );
return retv;
}
@ -230,28 +229,20 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat
}
static int combi_is_not_ascii ( const Mode *sw, unsigned int index )
{
CombiModePrivateData *pd = sw->private_data;
CombiModePrivateData *pd = mode_get_private_data ( sw );
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
return pd->switchers[i]->is_not_ascii ( pd->switchers[i], index - pd->starts[i] );
return mode_is_not_ascii ( pd->switchers[i], index - pd->starts[i] );
}
}
return FALSE;
}
static char * combi_get_completion ( const Mode *sw, unsigned int index )
{
CombiModePrivateData *pd = sw->private_data;
CombiModePrivateData *pd = mode_get_private_data ( sw );
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
char * str = NULL;
if ( pd->switchers[i]->get_completion != NULL ) {
str = pd->switchers[i]->get_completion ( pd->switchers[i], index - pd->starts[i] );
}
else {
int state;
str = pd->switchers[i]->mgrv ( pd->switchers[i], index - pd->starts[i], &state, TRUE );
}
return str;
return mode_get_completion ( pd->switchers[i], index - pd->starts[i] );
}
}
// Should never get here.
@ -259,20 +250,21 @@ static char * combi_get_completion ( const Mode *sw, unsigned int index )
return NULL;
}
#include "mode-private.h"
Mode combi_mode =
{
.name = "combi",
.keycfg = NULL,
.keystr = NULL,
.modmask = AnyModifier,
._init = combi_mode_init,
._get_num_entries = combi_mode_get_num_entries,
.result = combi_mode_result,
._destroy = combi_mode_destroy,
.token_match = combi_mode_match,
.get_completion = combi_get_completion,
.mgrv = combi_mgrv,
.is_not_ascii = combi_is_not_ascii,
.private_data = NULL,
.free = NULL
.name = "combi",
.keycfg = NULL,
.keystr = NULL,
.modmask = AnyModifier,
._init = combi_mode_init,
._get_num_entries = combi_mode_get_num_entries,
._result = combi_mode_result,
._destroy = combi_mode_destroy,
._token_match = combi_mode_match,
._get_completion = combi_get_completion,
._get_display_value = combi_mgrv,
._is_not_ascii = combi_is_not_ascii,
.private_data = NULL,
.free = NULL
};

View File

@ -40,7 +40,6 @@
#include "helper.h"
#include "xrmoptions.h"
#include "mode-private.h"
// We limit at 1000000 rows for now.
#define DMENU_MAX_ROWS 1000000
@ -109,7 +108,7 @@ static char **get_dmenu ( FILE *fd, unsigned int *length )
static unsigned int dmenu_mode_get_num_entries ( const Mode *sw )
{
const DmenuModePrivateData *rmpd = (const DmenuModePrivateData *) sw->private_data;
const DmenuModePrivateData *rmpd = (const DmenuModePrivateData *) mode_get_private_data ( sw );
return rmpd->cmd_list_length;
}
@ -151,7 +150,7 @@ static void parse_ranges ( char *input, struct range_pair **list, unsigned int *
static char *get_display_data ( const Mode *data, unsigned int index, int *state, int get_entry )
{
Mode *sw = (Mode *) data;
DmenuModePrivateData *pd = (DmenuModePrivateData *) sw->private_data;
DmenuModePrivateData *pd = (DmenuModePrivateData *) mode_get_private_data ( sw );
char **retv = (char * *) pd->cmd_list;
for ( unsigned int i = 0; i < pd->num_active_list; i++ ) {
if ( index >= pd->active_list[i].start && index <= pd->active_list[i].stop ) {
@ -224,10 +223,10 @@ static void dmenu_output_formatted_line ( const char *format, const char *string
}
static void dmenu_mode_free ( Mode *sw )
{
if ( sw->private_data == NULL ) {
if ( mode_get_private_data ( sw ) == NULL ) {
return;
}
DmenuModePrivateData *pd = (DmenuModePrivateData *) sw->private_data;
DmenuModePrivateData *pd = (DmenuModePrivateData *) mode_get_private_data ( sw );
if ( pd != NULL ) {
for ( size_t i = 0; i < pd->cmd_list_length; i++ ) {
if ( pd->cmd_list[i] ) {
@ -240,17 +239,17 @@ static void dmenu_mode_free ( Mode *sw )
g_free ( pd->selected_list );
g_free ( pd );
sw->private_data = NULL;
mode_set_private_data ( sw, NULL );
}
}
static void dmenu_mode_init ( Mode *sw )
{
if ( sw->private_data != NULL ) {
if ( mode_get_private_data ( sw ) != NULL ) {
return;
}
sw->private_data = g_malloc0 ( sizeof ( DmenuModePrivateData ) );
DmenuModePrivateData *pd = (DmenuModePrivateData *) sw->private_data;
mode_set_private_data ( sw, g_malloc0 ( sizeof ( DmenuModePrivateData ) ) );
DmenuModePrivateData *pd = (DmenuModePrivateData *) mode_get_private_data ( sw );
pd->prompt = "dmenu ";
pd->selected_line = UINT32_MAX;
@ -315,32 +314,33 @@ static void dmenu_mode_init ( Mode *sw )
static int dmenu_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
{
DmenuModePrivateData *rmpd = (DmenuModePrivateData *) sw->private_data;
DmenuModePrivateData *rmpd = (DmenuModePrivateData *) mode_get_private_data ( sw );
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );
}
static int dmenu_is_not_ascii ( const Mode *sw, unsigned int index )
{
DmenuModePrivateData *rmpd = (DmenuModePrivateData *) sw->private_data;
DmenuModePrivateData *rmpd = (DmenuModePrivateData *) mode_get_private_data ( sw );
return !g_str_is_ascii ( rmpd->cmd_list[index] );
}
#include "mode-private.h"
Mode dmenu_mode =
{
.name = "dmenu",
.keycfg = NULL,
.keystr = NULL,
.modmask = AnyModifier,
._init = dmenu_mode_init,
._get_num_entries = dmenu_mode_get_num_entries,
.result = NULL,
._destroy = dmenu_mode_free,
.token_match = dmenu_token_match,
.mgrv = get_display_data,
.get_completion = NULL,
.is_not_ascii = dmenu_is_not_ascii,
.private_data = NULL,
.free = NULL
.name = "dmenu",
.keycfg = NULL,
.keystr = NULL,
.modmask = AnyModifier,
._init = dmenu_mode_init,
._get_num_entries = dmenu_mode_get_num_entries,
._result = NULL,
._destroy = dmenu_mode_free,
._token_match = dmenu_token_match,
._get_display_value = get_display_data,
._get_completion = NULL,
._is_not_ascii = dmenu_is_not_ascii,
.private_data = NULL,
.free = NULL
};
int dmenu_switcher_dialog ( void )

View File

@ -43,8 +43,6 @@
#include "helper.h"
#include "dialogs/drun.h"
#include "mode-private.h"
#define RUN_CACHE_FILE "rofi-2.runcache"
static inline int execsh ( const char *cmd, int run_in_term )
@ -231,16 +229,16 @@ static void get_apps ( DRunModePrivateData *pd )
static void drun_mode_init ( Mode *sw )
{
if ( sw->private_data == NULL ) {
if ( mode_get_private_data ( sw ) == NULL ) {
DRunModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
sw->private_data = (void *) pd;
mode_set_private_data ( sw, (void *) pd );
get_apps ( pd );
}
}
static ModeMode drun_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
{
DRunModePrivateData *rmpd = (DRunModePrivateData *) sw->private_data;
DRunModePrivateData *rmpd = (DRunModePrivateData *) mode_get_private_data ( sw );
ModeMode retv = MODE_EXIT;
int shift = ( ( mretv & MENU_SHIFT ) == MENU_SHIFT );
@ -265,7 +263,7 @@ static ModeMode drun_mode_result ( Mode *sw, int mretv, char **input, unsigned i
static void drun_mode_destroy ( Mode *sw )
{
DRunModePrivateData *rmpd = (DRunModePrivateData *) sw->private_data;
DRunModePrivateData *rmpd = (DRunModePrivateData *) mode_get_private_data ( sw );
if ( rmpd != NULL ) {
for ( size_t i = 0; i < rmpd->cmd_list_length; i++ ) {
g_free ( rmpd->entry_list[i].exec );
@ -274,13 +272,13 @@ static void drun_mode_destroy ( Mode *sw )
}
g_free ( rmpd->entry_list );
g_free ( rmpd );
sw->private_data = NULL;
mode_set_private_data ( sw, NULL );
}
}
static char *mgrv ( const Mode *sw, unsigned int selected_line, int *state, int get_entry )
static char *_get_display_value ( const Mode *sw, unsigned int selected_line, int *state, int get_entry )
{
DRunModePrivateData *pd = (DRunModePrivateData *) sw->private_data;
DRunModePrivateData *pd = (DRunModePrivateData *) mode_get_private_data ( sw );
*state |= MARKUP;
if ( !get_entry ) {
return NULL;
@ -301,7 +299,7 @@ static char *mgrv ( const Mode *sw, unsigned int selected_line, int *state, int
}
static char *drun_get_completion ( const Mode *sw, unsigned int index )
{
DRunModePrivateData *pd = (DRunModePrivateData *) sw->private_data;
DRunModePrivateData *pd = (DRunModePrivateData *) mode_get_private_data ( sw );
/* Free temp storage. */
DRunModeEntry *dr = &( pd->entry_list[index] );
if ( dr->generic_name == NULL ) {
@ -319,7 +317,7 @@ static int drun_token_match ( const Mode *data,
unsigned int index
)
{
DRunModePrivateData *rmpd = (DRunModePrivateData *) data->private_data;
DRunModePrivateData *rmpd = (DRunModePrivateData *) mode_get_private_data ( data );
int match = 1;
if ( tokens ) {
for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) {
@ -347,32 +345,33 @@ static int drun_token_match ( const Mode *data,
static unsigned int drun_mode_get_num_entries ( const Mode *sw )
{
const DRunModePrivateData *pd = (const DRunModePrivateData *) sw->private_data;
const DRunModePrivateData *pd = (const DRunModePrivateData *) mode_get_private_data ( sw );
return pd->cmd_list_length;
}
static int drun_is_not_ascii ( const Mode *sw, unsigned int index )
{
DRunModePrivateData *pd = (DRunModePrivateData *) sw->private_data;
DRunModePrivateData *pd = (DRunModePrivateData *) mode_get_private_data ( sw );
if ( pd->entry_list[index].generic_name ) {
return !g_str_is_ascii ( pd->entry_list[index].name ) || !g_str_is_ascii ( pd->entry_list[index].generic_name );
}
return !g_str_is_ascii ( pd->entry_list[index].name );
}
#include "mode-private.h"
Mode drun_mode =
{
.name = "drun",
.keycfg = NULL,
.keystr = NULL,
.modmask = AnyModifier,
._init = drun_mode_init,
._get_num_entries = drun_mode_get_num_entries,
.result = drun_mode_result,
._destroy = drun_mode_destroy,
.token_match = drun_token_match,
.get_completion = drun_get_completion,
.mgrv = mgrv,
.is_not_ascii = drun_is_not_ascii,
.private_data = NULL,
.free = NULL
.name = "drun",
.keycfg = NULL,
.keystr = NULL,
.modmask = AnyModifier,
._init = drun_mode_init,
._get_num_entries = drun_mode_get_num_entries,
._result = drun_mode_result,
._destroy = drun_mode_destroy,
._token_match = drun_token_match,
._get_completion = drun_get_completion,
._get_display_value = _get_display_value,
._is_not_ascii = drun_is_not_ascii,
.private_data = NULL,
.free = NULL
};

View File

@ -363,7 +363,7 @@ static void run_mode_destroy ( Mode *sw )
}
}
static char *mgrv ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, int get_entry )
static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, int get_entry )
{
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
@ -379,21 +379,23 @@ static int run_is_not_ascii ( const Mode *sw, unsigned int index )
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
return !g_str_is_ascii ( rmpd->cmd_list[index] );
}
#include "mode-private.h"
Mode run_mode =
{
.name = "run",
.keycfg = NULL,
.keystr = NULL,
.modmask = AnyModifier,
._init = run_mode_init,
._get_num_entries = run_mode_get_num_entries,
.result = run_mode_result,
._destroy = run_mode_destroy,
.token_match = run_token_match,
.mgrv = mgrv,
.get_completion = NULL,
.is_not_ascii = run_is_not_ascii,
.private_data = NULL,
.free = NULL
.name = "run",
.keycfg = NULL,
.keystr = NULL,
.modmask = AnyModifier,
._init = run_mode_init,
._get_num_entries = run_mode_get_num_entries,
._result = run_mode_result,
._destroy = run_mode_destroy,
._token_match = run_token_match,
._get_display_value = _get_display_value,
._get_completion = NULL,
._is_not_ascii = run_is_not_ascii,
.private_data = NULL,
.free = NULL
};
/*@}*/

View File

@ -157,7 +157,7 @@ static void script_mode_destroy ( Mode *sw )
sw->private_data = NULL;
}
}
static char *mgrv ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, int get_entry )
static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, int get_entry )
{
ScriptModePrivateData *rmpd = sw->private_data;
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
@ -175,6 +175,7 @@ static int script_is_not_ascii ( const Mode *sw, unsigned int index )
return !g_str_is_ascii ( rmpd->cmd_list[index] );
}
#include "mode-private.h"
Mode *script_switcher_parse_setup ( const char *str )
{
Mode *sw = g_malloc0 ( sizeof ( *sw ) );
@ -192,17 +193,17 @@ Mode *script_switcher_parse_setup ( const char *str )
}
g_free ( parse );
if ( index == 2 ) {
sw->free = script_switcher_free;
sw->keysym = None;
sw->modmask = AnyModifier;
sw->_init = script_mode_init;
sw->_get_num_entries = script_mode_get_num_entries;
sw->result = script_mode_result;
sw->_destroy = script_mode_destroy;
sw->token_match = script_token_match;
sw->get_completion = NULL,
sw->mgrv = mgrv;
sw->is_not_ascii = script_is_not_ascii;
sw->free = script_switcher_free;
sw->keysym = None;
sw->modmask = AnyModifier;
sw->_init = script_mode_init;
sw->_get_num_entries = script_mode_get_num_entries;
sw->_result = script_mode_result;
sw->_destroy = script_mode_destroy;
sw->_token_match = script_token_match;
sw->_get_completion = NULL,
sw->_get_display_value = _get_display_value;
sw->_is_not_ascii = script_is_not_ascii;
return sw;
}

View File

@ -48,7 +48,6 @@
#include "history.h"
#include "dialogs/ssh.h"
#include "mode-private.h"
/**
* Name of the history file where previously choosen hosts are stored.
*/
@ -365,10 +364,10 @@ typedef struct _SSHModePrivateData
*/
static void ssh_mode_init ( Mode *sw )
{
if ( sw->private_data == NULL ) {
if ( mode_get_private_data ( sw ) == NULL ) {
SSHModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
sw->private_data = (void *) pd;
pd->hosts_list = get_ssh ( &( pd->hosts_list_length ) );
mode_set_private_data ( sw, (void *) pd );
pd->hosts_list = get_ssh ( &( pd->hosts_list_length ) );
}
}
@ -381,7 +380,7 @@ static void ssh_mode_init ( Mode *sw )
*/
static unsigned int ssh_mode_get_num_entries ( const Mode *sw )
{
const SSHModePrivateData *rmpd = (const SSHModePrivateData *) sw->private_data;
const SSHModePrivateData *rmpd = (const SSHModePrivateData *) mode_get_private_data ( sw );
return rmpd->hosts_list_length;
}
@ -398,7 +397,7 @@ static unsigned int ssh_mode_get_num_entries ( const Mode *sw )
static ModeMode ssh_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
{
ModeMode retv = MODE_EXIT;
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
if ( mretv & MENU_NEXT ) {
retv = NEXT_DIALOG;
}
@ -432,11 +431,11 @@ static ModeMode ssh_mode_result ( Mode *sw, int mretv, char **input, unsigned in
*/
static void ssh_mode_destroy ( Mode *sw )
{
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
if ( rmpd != NULL ) {
g_strfreev ( rmpd->hosts_list );
g_free ( rmpd );
sw->private_data = NULL;
mode_set_private_data ( sw, NULL );
}
}
@ -451,9 +450,9 @@ static void ssh_mode_destroy ( Mode *sw )
*
* @return the string as it should be displayed and the display state.
*/
static char *mgrv ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, int get_entry )
static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, int get_entry )
{
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
return get_entry ? g_strdup ( rmpd->hosts_list[selected_line] ) : NULL;
}
@ -470,7 +469,7 @@ static char *mgrv ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED in
*/
static int ssh_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
{
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
return token_match ( tokens, rmpd->hosts_list[index], not_ascii, case_sensitive );
}
@ -484,25 +483,26 @@ static int ssh_token_match ( const Mode *sw, char **tokens, int not_ascii, int c
*/
static int ssh_is_not_ascii ( const Mode *sw, unsigned int index )
{
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
return !g_str_is_ascii ( rmpd->hosts_list[index] );
}
#include "mode-private.h"
Mode ssh_mode =
{
.name = "ssh",
.keycfg = NULL,
.keystr = NULL,
.modmask = AnyModifier,
._init = ssh_mode_init,
._get_num_entries = ssh_mode_get_num_entries,
.result = ssh_mode_result,
._destroy = ssh_mode_destroy,
.token_match = ssh_token_match,
.mgrv = mgrv,
.get_completion = NULL,
.is_not_ascii = ssh_is_not_ascii,
.private_data = NULL,
.free = NULL
.name = "ssh",
.keycfg = NULL,
.keystr = NULL,
.modmask = AnyModifier,
._init = ssh_mode_init,
._get_num_entries = ssh_mode_get_num_entries,
._result = ssh_mode_result,
._destroy = ssh_mode_destroy,
._token_match = ssh_token_match,
._get_display_value = _get_display_value,
._get_completion = NULL,
._is_not_ascii = ssh_is_not_ascii,
.private_data = NULL,
.free = NULL
};
/*@}*/

View File

@ -44,7 +44,6 @@
#include "x11-helper.h"
#include "i3-support.h"
#include "dialogs/window.h"
#include "mode-private.h"
#define WINLIST 32
@ -326,7 +325,7 @@ static int window_match ( const Mode *sw, char **tokens,
__attribute__( ( unused ) ) int not_ascii,
int case_sensitive, unsigned int index )
{
ModeModePrivateData *rmpd = (ModeModePrivateData *) sw->private_data;
ModeModePrivateData *rmpd = (ModeModePrivateData *) mode_get_private_data ( sw );
int match = 1;
const winlist *ids = ( winlist * ) rmpd->ids;
// Want to pull directly out of cache, X calls are not thread safe.
@ -369,12 +368,12 @@ static int window_match ( const Mode *sw, char **tokens,
static unsigned int window_mode_get_num_entries ( const Mode *sw )
{
const ModeModePrivateData *pd = (const ModeModePrivateData *) sw->private_data;
const ModeModePrivateData *pd = (const ModeModePrivateData *) mode_get_private_data ( sw );
return pd->cmd_list_length;
}
static void _window_mode_load_data ( Mode *sw, unsigned int cd )
{
ModeModePrivateData *pd = (ModeModePrivateData *) sw->private_data;
ModeModePrivateData *pd = (ModeModePrivateData *) mode_get_private_data ( sw );
Screen *screen = DefaultScreenOfDisplay ( display );
Window root = RootWindow ( display, XScreenNumberOfScreen ( screen ) );
// find window list
@ -498,24 +497,24 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
}
static void window_mode_init ( Mode *sw )
{
if ( sw->private_data == NULL ) {
if ( mode_get_private_data ( sw ) == NULL ) {
ModeModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
sw->private_data = (void *) pd;
mode_set_private_data ( sw, (void *) pd );
_window_mode_load_data ( sw, FALSE );
}
}
static void window_mode_init_cd ( Mode *sw )
{
if ( sw->private_data == NULL ) {
if ( mode_get_private_data ( sw ) == NULL ) {
ModeModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
sw->private_data = (void *) pd;
mode_set_private_data ( sw, (void *) pd );
_window_mode_load_data ( sw, TRUE );
}
}
static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **input,
unsigned int selected_line )
{
ModeModePrivateData *rmpd = (ModeModePrivateData *) sw->private_data;
ModeModePrivateData *rmpd = (ModeModePrivateData *) mode_get_private_data ( sw );
ModeMode retv = MODE_EXIT;
if ( mretv & MENU_NEXT ) {
retv = NEXT_DIALOG;
@ -549,7 +548,7 @@ static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **i
static void window_mode_destroy ( Mode *sw )
{
ModeModePrivateData *rmpd = (ModeModePrivateData *) sw->private_data;
ModeModePrivateData *rmpd = (ModeModePrivateData *) mode_get_private_data ( sw );
if ( rmpd != NULL ) {
g_strfreev ( rmpd->cmd_list );
winlist_free ( rmpd->ids );
@ -557,13 +556,13 @@ static void window_mode_destroy ( Mode *sw )
x11_cache_free ();
g_free ( rmpd->cache );
g_free ( rmpd );
sw->private_data = NULL;
mode_set_private_data ( sw, NULL );
}
}
static char *mgrv ( const Mode *sw, unsigned int selected_line, int *state, int get_entry )
static char *_get_display_value ( const Mode *sw, unsigned int selected_line, int *state, int get_entry )
{
ModeModePrivateData *rmpd = sw->private_data;
ModeModePrivateData *rmpd = mode_get_private_data ( sw );
if ( window_client ( display, rmpd->ids->array[selected_line] )->demands ) {
*state |= URGENT;
}
@ -575,7 +574,7 @@ static char *mgrv ( const Mode *sw, unsigned int selected_line, int *state, int
static int window_is_not_ascii ( const Mode *sw, unsigned int index )
{
const ModeModePrivateData *rmpd = sw->private_data;
const ModeModePrivateData *rmpd = mode_get_private_data ( sw );
const winlist *ids = ( winlist * ) rmpd->ids;
// Want to pull directly out of cache, X calls are not thread safe.
int idx = winlist_find ( cache_client, ids->array[index] );
@ -584,39 +583,40 @@ static int window_is_not_ascii ( const Mode *sw, unsigned int index )
return !g_str_is_ascii ( c->role ) || !g_str_is_ascii ( c->class ) || !g_str_is_ascii ( c->title ) || !g_str_is_ascii ( c->name );
}
#include "mode-private.h"
Mode window_mode =
{
.name = "window",
.keycfg = NULL,
.keystr = NULL,
.modmask = AnyModifier,
._init = window_mode_init,
._get_num_entries = window_mode_get_num_entries,
.result = window_mode_result,
._destroy = window_mode_destroy,
.token_match = window_match,
.mgrv = mgrv,
.get_completion = NULL,
.is_not_ascii = window_is_not_ascii,
.private_data = NULL,
.free = NULL
.name = "window",
.keycfg = NULL,
.keystr = NULL,
.modmask = AnyModifier,
._init = window_mode_init,
._get_num_entries = window_mode_get_num_entries,
._result = window_mode_result,
._destroy = window_mode_destroy,
._token_match = window_match,
._get_display_value = _get_display_value,
._get_completion = NULL,
._is_not_ascii = window_is_not_ascii,
.private_data = NULL,
.free = NULL
};
Mode window_mode_cd =
{
.name = "windowcd",
.keycfg = NULL,
.keystr = NULL,
.modmask = AnyModifier,
._init = window_mode_init_cd,
._get_num_entries = window_mode_get_num_entries,
.result = window_mode_result,
._destroy = window_mode_destroy,
.token_match = window_match,
.mgrv = mgrv,
.get_completion = NULL,
.is_not_ascii = window_is_not_ascii,
.private_data = NULL,
.free = NULL
.name = "windowcd",
.keycfg = NULL,
.keystr = NULL,
.modmask = AnyModifier,
._init = window_mode_init_cd,
._get_num_entries = window_mode_get_num_entries,
._result = window_mode_result,
._destroy = window_mode_destroy,
._token_match = window_match,
._get_display_value = _get_display_value,
._get_completion = NULL,
._is_not_ascii = window_is_not_ascii,
.private_data = NULL,
.free = NULL
};
#endif // WINDOW_MODE

View File

@ -1,4 +1,6 @@
#include "rofi.h"
#include "xrmoptions.h"
#include "x11-helper.h"
#include "mode.h"
// This one should only be in mode implementations.
@ -32,8 +34,126 @@ unsigned int mode_get_num_entries ( const Mode *mode )
char * mode_get_display_value ( const Mode *mode, unsigned int selected_line, int *state, int get_entry )
{
g_assert ( mode != NULL );
g_assert ( mode->mgrv != NULL );
g_assert ( mode->_get_display_value != NULL );
return mode->mgrv ( mode, selected_line, state, get_entry );
return mode->_get_display_value ( mode, selected_line, state, get_entry );
}
char * mode_get_completion ( const Mode *mode, unsigned int selected_line )
{
g_assert ( mode != NULL );
if ( mode->_get_completion != NULL ) {
return mode->_get_completion ( mode, selected_line );
}
else {
int state;
g_assert ( mode->_get_display_value != NULL );
return mode->_get_display_value ( mode, selected_line, &state, TRUE );
}
}
int mode_is_not_ascii ( const Mode *mode, unsigned int selected_line )
{
g_assert ( mode != NULL );
g_assert ( mode->_is_not_ascii != NULL );
return mode->_is_not_ascii ( mode, selected_line );
}
ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int selected_line )
{
g_assert ( mode != NULL );
g_assert ( mode->_result != NULL );
return mode->_result ( mode, menu_retv, input, selected_line );
}
int mode_token_match ( const Mode *mode, char **tokens, int not_ascii, int case_sensitive, unsigned int selected_line )
{
g_assert ( mode != NULL );
g_assert ( mode->_token_match != NULL );
return mode->_token_match ( mode, tokens, not_ascii, case_sensitive, selected_line );
}
const char *mode_get_name ( const Mode *mode )
{
g_assert ( mode != NULL );
return mode->name;
}
void mode_setup_keybinding ( Mode *mode )
{
g_assert ( mode != NULL );
mode->keycfg = g_strdup_printf ( "key-%s", mode->name );
config_parser_add_option ( xrm_String, mode->keycfg, (void * *) &( mode->keystr ), "Keybinding" );
}
int mode_check_keybinding ( const Mode *mode, KeySym key, unsigned int modstate )
{
g_assert ( mode != NULL );
if ( mode->keystr != NULL ) {
if ( mode->modmask == modstate && mode->keysym == key ) {
return TRUE;
}
}
return FALSE;
}
void mode_free ( Mode **mode )
{
g_assert ( mode != NULL );
if ( ( *mode )->keycfg != NULL ) {
g_free ( ( *mode )->keycfg );
( *mode )->keycfg = NULL;
}
if ( ( *mode )->free != NULL ) {
( *mode )->free ( *mode );
}
( *mode ) = NULL;
}
int mode_grab_key ( Mode *mode, Display *display )
{
g_assert ( mode != NULL );
if ( mode->keystr != NULL ) {
x11_parse_key ( mode->keystr, &( mode->modmask ), &( mode->keysym ) );
if ( mode->keysym != NoSymbol ) {
x11_grab_key ( display, mode->modmask, mode->keysym );
return TRUE;
}
}
return FALSE;
}
void mode_ungrab_key ( Mode *mode, Display *display )
{
g_assert ( mode != NULL );
if ( mode->keystr != NULL ) {
if ( mode->keysym != NoSymbol ) {
x11_ungrab_key ( display, mode->modmask, mode->keysym );
}
}
}
void mode_print_keybindings ( const Mode *mode )
{
g_assert ( mode != NULL );
if ( mode->keystr != NULL ) {
fprintf ( stdout, "\t* "color_bold "%s"color_reset " on %s\n", mode->name, mode->keystr );
}
else {
fprintf ( stdout, "\t* "color_bold "%s"color_reset " on <unspecified>\n", mode->name );
}
}
void *mode_get_private_data ( const Mode *mode )
{
g_assert ( mode != NULL );
return mode->private_data;
}
void mode_set_private_data ( Mode *mode, void *pd )
{
g_assert ( mode != NULL );
if ( pd != NULL ) {
g_assert ( mode->private_data == NULL );
}
mode->private_data = pd;
}
/*@}*/

View File

@ -60,8 +60,6 @@
#include "xrmoptions.h"
#include "dialogs/dialogs.h"
// This one should only be in mode implementations.
#include "mode-private.h"
ModeMode switcher_run ( char **input, Mode *sw );
typedef enum _MainLoopEvent
@ -130,7 +128,7 @@ static char * get_matching_state ( void )
static int switcher_get ( const char *name )
{
for ( unsigned int i = 0; i < num_modi; i++ ) {
if ( strcmp ( modi[i].sw->name, name ) == 0 ) {
if ( strcmp ( mode_get_name ( modi[i].sw ), name ) == 0 ) {
return i;
}
}
@ -580,11 +578,8 @@ static int locate_switcher ( KeySym key, unsigned int modstate )
// ignore annoying modifiers
unsigned int modstate_filtered = modstate & ~( LockMask | NumlockMask );
for ( unsigned int i = 0; i < num_modi; i++ ) {
if ( modi[i].sw->keystr != NULL ) {
if ( ( modstate_filtered == modi[i].sw->modmask ) &&
modi[i].sw->keysym == key ) {
return i;
}
if ( mode_check_keybinding ( modi[i].sw, key, modstate_filtered ) ) {
return i;
}
}
return -1;
@ -714,14 +709,7 @@ static int menu_keyboard_navigation ( MenuState *state, KeySym key, unsigned int
else if ( abe_test_action ( ROW_SELECT, modstate, key ) ) {
// If a valid item is selected, return that..
if ( state->selected < state->filtered_lines ) {
int st;
char *str = NULL;
if ( state->sw->get_completion ) {
str = state->sw->get_completion ( state->sw, state->line_map[state->selected] );
}
else {
str = state->sw->mgrv ( state->sw, state->line_map[state->selected], &st, TRUE );
}
char *str = mode_get_completion ( state->sw, state->line_map[state->selected] );
textbox_text ( state->text, str );
g_free ( str );
textbox_cursor_end ( state->text );
@ -832,23 +820,16 @@ static void filter_elements ( thread_state *t, G_GNUC_UNUSED gpointer user_data
{
// input changed
for ( unsigned int i = t->start; i < t->stop; i++ ) {
int st;
int match = t->state->sw->token_match ( t->state->sw, t->tokens,
t->state->lines_not_ascii[i],
config.case_sensitive,
i );
int match = mode_token_match ( t->state->sw, t->tokens,
t->state->lines_not_ascii[i],
config.case_sensitive,
i );
// If each token was matched, add it to list.
if ( match ) {
t->state->line_map[t->start + t->count] = i;
if ( config.levenshtein_sort ) {
// This is inefficient, need to fix it.
char * str = NULL;
if ( t->state->sw->get_completion ) {
str = t->state->sw->get_completion ( t->state->sw, i );
}
else{
str = t->state->sw->mgrv ( t->state->sw, i, &st, TRUE );
}
char * str = mode_get_completion ( t->state->sw, i );
t->state->distance[i] = levenshtein ( t->state->text->text, str );
g_free ( str );
}
@ -863,7 +844,7 @@ static void filter_elements ( thread_state *t, G_GNUC_UNUSED gpointer user_data
static void check_is_ascii ( thread_state *t, G_GNUC_UNUSED gpointer user_data )
{
for ( unsigned int i = t->start; i < t->stop; i++ ) {
t->state->lines_not_ascii[i] = t->state->sw->is_not_ascii ( t->state->sw, i );
t->state->lines_not_ascii[i] = mode_is_not_ascii ( t->state->sw, i );
}
g_mutex_lock ( t->mutex );
( *( t->acount ) )--;
@ -1438,7 +1419,7 @@ MenuReturn menu ( Mode *sw, char **input, char *prompt, unsigned int *selected_l
for ( unsigned int j = 0; j < num_modi; j++ ) {
modi[j].tb = textbox_create ( TB_CENTER, state.border + j * ( width + config.line_margin ),
state.h - state.line_height - state.border, width, state.line_height,
( j == curr_switcher ) ? HIGHLIGHT : NORMAL, modi[j].sw->name );
( j == curr_switcher ) ? HIGHLIGHT : NORMAL, mode_get_name ( modi[j].sw ) );
}
}
@ -2021,15 +2002,7 @@ static void cleanup ()
// Cleaning up memory allocated by the Xresources file.
config_xresource_free ();
for ( unsigned int i = 0; i < num_modi; i++ ) {
// Mode keystr is free'ed when needed by config system.
if ( modi[i].sw->keycfg != NULL ) {
g_free ( modi[i].sw->keycfg );
modi[i].sw->keycfg = NULL;
}
// only used for script dialog.
if ( modi[i].sw->free != NULL ) {
modi[i].sw->free ( modi[i].sw );
}
mode_free ( &( modi[i].sw ) );
}
g_free ( modi );
@ -2110,8 +2083,7 @@ static void setup_modi ( void )
// We cannot do this in main loop, as we create pointer to string,
// and re-alloc moves that pointer.
for ( unsigned int i = 0; i < num_modi; i++ ) {
modi[i].sw->keycfg = g_strdup_printf ( "key-%s", modi[i].sw->name );
config_parser_add_option ( xrm_String, modi[i].sw->keycfg, (void * *) &( modi[i].sw->keystr ), "Keybinding" );
mode_setup_keybinding ( modi[i].sw );
}
}
@ -2140,24 +2112,15 @@ static inline void load_configuration_dynamic ( Display *display )
static void release_global_keybindings ()
{
for ( unsigned int i = 0; i < num_modi; i++ ) {
if ( modi[i].sw->keystr != NULL ) {
// No need to parse key, this should be done when grabbing.
if ( modi[i].sw->keysym != NoSymbol ) {
x11_ungrab_key ( display, modi[i].sw->modmask, modi[i].sw->keysym );
}
}
mode_ungrab_key ( modi[i].sw, display );
}
}
static int grab_global_keybindings ()
{
int key_bound = FALSE;
for ( unsigned int i = 0; i < num_modi; i++ ) {
if ( modi[i].sw->keystr != NULL ) {
x11_parse_key ( modi[i].sw->keystr, &( modi[i].sw->modmask ), &( modi[i].sw->keysym ) );
if ( modi[i].sw->keysym != NoSymbol ) {
x11_grab_key ( display, modi[i].sw->modmask, modi[i].sw->keysym );
key_bound = TRUE;
}
if ( mode_grab_key ( modi[i].sw, display ) ) {
key_bound = TRUE;
}
}
return key_bound;
@ -2166,12 +2129,7 @@ static void print_global_keybindings ()
{
fprintf ( stdout, "listening to the following keys:\n" );
for ( unsigned int i = 0; i < num_modi; i++ ) {
if ( modi[i].sw->keystr != NULL ) {
fprintf ( stdout, "\t* "color_bold "%s"color_reset " on %s\n", modi[i].sw->name, modi[i].sw->keystr );
}
else {
fprintf ( stdout, "\t* "color_bold "%s"color_reset " on <unspecified>\n", modi[i].sw->name );
}
mode_print_keybindings ( modi[i].sw );
}
}
@ -2325,11 +2283,11 @@ static int main_loop_signal_handler ( char command, int quiet )
ModeMode switcher_run ( char **input, Mode *sw )
{
char *prompt = g_strdup_printf ( "%s:", sw->name );
char *prompt = g_strdup_printf ( "%s:", mode_get_name ( sw ) );
unsigned int selected_line = UINT32_MAX;
int mretv = menu ( sw, input, prompt, &selected_line, NULL, NULL );
g_free ( prompt );
return sw->result ( sw, mretv, input, selected_line );
return mode_result ( sw, mretv, input, selected_line );
}
/**
@ -2563,7 +2521,8 @@ int main ( int argc, char *argv[] )
fprintf ( stderr, "Please check the manpage on how to specify a key-binding.\n" );
fprintf ( stderr, "The following modi are enabled and keys can be specified:\n" );
for ( unsigned int i = 0; i < num_modi; i++ ) {
fprintf ( stderr, "\t* "color_bold "%s"color_reset ": -key-%s <key>\n", modi[i].sw->name, modi[i].sw->name );
const char *name = mode_get_name ( modi[i].sw );
fprintf ( stderr, "\t* "color_bold "%s"color_reset ": -key-%s <key>\n", name, name );
}
return EXIT_FAILURE;
}

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# wait till it is up, run rofi with error message
sleep 1 && rofi -show run -display :201 &
sleep 1 && rofi -show run -modi run &
RPID=$!
# send enter.

View File

@ -8,6 +8,7 @@ function create_fake_x ( )
echo "Starting fake X: ${DISPLAY}"
Xvfb ${DISPLAY} &
XPID=$!
sleep 1;
fluxbox &
FPID=$!
sleep 1