summaryrefslogtreecommitdiffstats
path: root/source
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 /source
parente8daff0f6ad49cd17b225622fa1875ee2960a70f (diff)
More splitting and abstracting.
Diffstat (limited to 'source')
-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
9 files changed, 334 insertions, 261 deletions
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 ) == 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
};
/*@}*/
diff --git a/source/dialogs/window.c b/source/dialogs/window.c
index e1ee71d0..faadd8d3 100644
--- a/source/dialogs/window.c
+++ b/source/dialogs/window.c
@@ -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