summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-01-07 21:27:20 +0100
committerDave Davenport <qball@gmpclient.org>2016-01-07 21:27:20 +0100
commitfa51aeb484374cf22493d0da81e298a9052f1451 (patch)
tree245055e789ece34b0b6945cc0e949ea4a599e2fc
parente8daff0f6ad49cd17b225622fa1875ee2960a70f (diff)
More splitting and abstracting.
-rw-r--r--include/mode-private.h34
-rw-r--r--include/mode.h86
-rw-r--r--include/textbox.h16
-rw-r--r--source/dialogs/combi.c92
-rw-r--r--source/dialogs/dmenu.c50
-rw-r--r--source/dialogs/drun.c53
-rw-r--r--source/dialogs/run.c32
-rw-r--r--source/dialogs/script.c25
-rw-r--r--source/dialogs/ssh.c52
-rw-r--r--source/dialogs/window.c84
-rw-r--r--source/mode.c124
-rw-r--r--source/rofi.c83
-rwxr-xr-xtest/run_switchdialog_test.sh2
-rwxr-xr-xtest/run_test.sh1
14 files changed, 447 insertions, 287 deletions
diff --git a/include/mode-private.h b/include/mode-private.h
index f8bf9879..9c02d847 100644
--- a/include/mode-private.h
+++ b/include/mode-private.h
@@ -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
diff --git a/include/mode.h b/include/mode.h
index 8a8d62a6..e20391cc 100644
--- a/include/mode.h
+++ b/include/mode.h
@@ -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
diff --git a/include/textbox.h b/include/textbox.h
index daa57aff..cc8c6494 100644
--- a/include/textbox.h
+++ b/include/textbox.h
@@ -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
diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c
index 0ee4d9f4..06319eaf 100644
--- a/source/dialogs/combi.c
+++ b/source/dialogs/combi.c
@@ -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
};
diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c
index a73c00cf..18c75b24 100644
--- a/source/dialogs/dmenu.c
+++ b/source/dialogs/dmenu.c
@@ -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 )
diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c
index 93d3307e..79b058c3 100644
--- a/source/dialogs/drun.c
+++ b/source/dialogs/drun.c
@@ -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
};
diff --git a/source/dialogs/run.c b/source/dialogs/run.c
index 7677f452..5de126a7 100644
--- a/source/dialogs/run.c
+++ b/source/dialogs/run.c
@@ -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
};
/*@}*/
diff --git a/source/dialogs/script.c b/source/dialogs/script.c
index 68147bf7..9943b6d1 100644
--- a/source/dialogs/script.c
+++ b/source/dialogs/script.c
@@ -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;
}
diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c
index 2c244f9b..05373417 100644
--- a/source/dialogs/ssh.c
+++ b/source/dialogs/ssh.c
@@ -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 )