mirror of
https://github.com/lbonn/rofi
synced 2025-02-18 13:58:30 +00:00
Big rename from Switcher to Mode internal, to match with user terminology
This commit is contained in:
parent
b7ec4fa6fb
commit
3c411433b4
17 changed files with 242 additions and 242 deletions
|
@ -29,9 +29,9 @@
|
||||||
#include "rofi.h"
|
#include "rofi.h"
|
||||||
|
|
||||||
Settings config = {
|
Settings config = {
|
||||||
/** List of enabled switchers. */
|
/** List of enabled modi. */
|
||||||
/** -switchers */
|
/** -modi */
|
||||||
.switchers = "window,run,ssh",
|
.modi = "window,run,ssh",
|
||||||
/** Set the default window opacity. */
|
/** Set the default window opacity. */
|
||||||
/** This option only works when running a composite manager. */
|
/** This option only works when running a composite manager. */
|
||||||
/** -o */
|
/** -o */
|
||||||
|
@ -118,7 +118,7 @@ Settings config = {
|
||||||
.separator = '\n',
|
.separator = '\n',
|
||||||
/** Height of an element in #chars */
|
/** Height of an element in #chars */
|
||||||
.element_height = 1,
|
.element_height = 1,
|
||||||
/** Sidebar mode, show the switchers */
|
/** Sidebar mode, show the modi */
|
||||||
.sidebar_mode = FALSE,
|
.sidebar_mode = FALSE,
|
||||||
/** Lazy mode setting */
|
/** Lazy mode setting */
|
||||||
.lazy_filter_limit = 15000,
|
.lazy_filter_limit = 15000,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef __COMBI_DIALOG_H__
|
#ifndef __COMBI_DIALOG_H__
|
||||||
#define __COMBI_DIALOG_H__
|
#define __COMBI_DIALOG_H__
|
||||||
|
|
||||||
extern Switcher combi_mode;
|
extern Mode combi_mode;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef __DRUN_DIALOG_H__
|
#ifndef __DRUN_DIALOG_H__
|
||||||
#define __DRUN_DIALOG_H__
|
#define __DRUN_DIALOG_H__
|
||||||
|
|
||||||
extern Switcher drun_mode;
|
extern Mode drun_mode;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef __RUN_DIALOG_H__
|
#ifndef __RUN_DIALOG_H__
|
||||||
#define __RUN_DIALOG_H__
|
#define __RUN_DIALOG_H__
|
||||||
|
|
||||||
extern Switcher run_mode;
|
extern Mode run_mode;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,5 +9,5 @@
|
||||||
*
|
*
|
||||||
* @returns NULL when it fails, a newly allocated ScriptOptions when successful.
|
* @returns NULL when it fails, a newly allocated ScriptOptions when successful.
|
||||||
*/
|
*/
|
||||||
Switcher *script_switcher_parse_setup ( const char *str );
|
Mode *script_switcher_parse_setup ( const char *str );
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef __SSH_DIALOG_H__
|
#ifndef __SSH_DIALOG_H__
|
||||||
#define __SSH_DIALOG_H__
|
#define __SSH_DIALOG_H__
|
||||||
|
|
||||||
extern Switcher ssh_mode;
|
extern Mode ssh_mode;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#ifdef WINDOW_MODE
|
#ifdef WINDOW_MODE
|
||||||
|
|
||||||
extern Switcher window_mode;
|
extern Mode window_mode;
|
||||||
extern Switcher window_mode_cd;
|
extern Mode window_mode_cd;
|
||||||
#endif // WINDOW_MODE
|
#endif // WINDOW_MODE
|
||||||
#endif // __WINDOW_DIALOG_H__
|
#endif // __WINDOW_DIALOG_H__
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
extern const char *cache_dir;
|
extern const char *cache_dir;
|
||||||
|
|
||||||
typedef struct _Switcher Switcher;
|
typedef struct _Mode Mode;
|
||||||
/**
|
/**
|
||||||
* Enum used to sum the possible states of ROFI.
|
* Enum used to sum the possible states of ROFI.
|
||||||
*/
|
*/
|
||||||
|
@ -29,7 +29,7 @@ typedef enum
|
||||||
RELOAD_DIALOG = 1002,
|
RELOAD_DIALOG = 1002,
|
||||||
/** Previous dialog */
|
/** Previous dialog */
|
||||||
PREVIOUS_DIALOG = 1003
|
PREVIOUS_DIALOG = 1003
|
||||||
} SwitcherMode;
|
} ModeMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* State returned by the rofi window.
|
* State returned by the rofi window.
|
||||||
|
@ -96,7 +96,7 @@ typedef enum _WindowLocation
|
||||||
} WindowLocation;
|
} WindowLocation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param sw the Switcher to show.
|
* @param sw the Mode to show.
|
||||||
* @param lines An array of strings to display.
|
* @param lines An array of strings to display.
|
||||||
* @param num_lines Length of the array with strings to display.
|
* @param num_lines Length of the array with strings to display.
|
||||||
* @param input A pointer to a string where the inputted data is placed.
|
* @param input A pointer to a string where the inputted data is placed.
|
||||||
|
@ -111,7 +111,7 @@ typedef enum _WindowLocation
|
||||||
*
|
*
|
||||||
* @returns The command issued (see MenuReturn)
|
* @returns The command issued (see MenuReturn)
|
||||||
*/
|
*/
|
||||||
MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *selected_line, unsigned int *next_pos, const char *message )
|
MenuReturn menu ( Mode *sw, char **input, char *prompt, unsigned int *selected_line, unsigned int *next_pos, const char *message )
|
||||||
__attribute__ ( ( nonnull ( 1, 2, 3, 4 ) ) );
|
__attribute__ ( ( nonnull ( 1, 2, 3, 4 ) ) );
|
||||||
/**
|
/**
|
||||||
* Settings
|
* Settings
|
||||||
|
@ -119,8 +119,8 @@ __attribute__ ( ( nonnull ( 1, 2, 3, 4 ) ) );
|
||||||
|
|
||||||
typedef struct _Settings
|
typedef struct _Settings
|
||||||
{
|
{
|
||||||
/** List of enabled switchers */
|
/** List of enabled modi */
|
||||||
char *switchers;
|
char *modi;
|
||||||
/** Window settings */
|
/** Window settings */
|
||||||
unsigned int window_opacity;
|
unsigned int window_opacity;
|
||||||
/** Border width */
|
/** Border width */
|
||||||
|
@ -193,7 +193,7 @@ typedef struct _Settings
|
||||||
char separator;
|
char separator;
|
||||||
/** Height of an element in #chars */
|
/** Height of an element in #chars */
|
||||||
int element_height;
|
int element_height;
|
||||||
/** Sidebar mode, show the switchers */
|
/** Sidebar mode, show the modi */
|
||||||
unsigned int sidebar_mode;
|
unsigned int sidebar_mode;
|
||||||
/** Lazy filter limit. */
|
/** Lazy filter limit. */
|
||||||
unsigned int lazy_filter_limit;
|
unsigned int lazy_filter_limit;
|
||||||
|
@ -203,7 +203,7 @@ typedef struct _Settings
|
||||||
unsigned int parse_hosts;
|
unsigned int parse_hosts;
|
||||||
/** Knonw_hosts file parsing */
|
/** Knonw_hosts file parsing */
|
||||||
unsigned int parse_known_hosts;
|
unsigned int parse_known_hosts;
|
||||||
/** Combi Switchers */
|
/** Combi Modes */
|
||||||
char *combi_modi;
|
char *combi_modi;
|
||||||
/** Fuzzy match */
|
/** Fuzzy match */
|
||||||
unsigned int fuzzy;
|
unsigned int fuzzy;
|
||||||
|
@ -243,11 +243,11 @@ extern Settings config;
|
||||||
*/
|
*/
|
||||||
void error_dialog ( const char *msg, int markup );
|
void error_dialog ( const char *msg, int markup );
|
||||||
|
|
||||||
typedef void ( *switcher_free )( Switcher *data );
|
typedef void ( *switcher_free )( Mode *data );
|
||||||
|
|
||||||
typedef char * ( *switcher_get_display_value )( const Switcher *sw, unsigned int selected_line, int *state, int get_entry );
|
typedef char * ( *switcher_get_display_value )( const Mode *sw, unsigned int selected_line, int *state, int get_entry );
|
||||||
|
|
||||||
typedef char * ( *switcher_get_completion )( const Switcher *sw, unsigned int selected_line );
|
typedef char * ( *switcher_get_completion )( const Mode *sw, unsigned int selected_line );
|
||||||
/**
|
/**
|
||||||
* @param tokens List of (input) tokens to match.
|
* @param tokens List of (input) tokens to match.
|
||||||
* @param input The entry to match against.
|
* @param input The entry to match against.
|
||||||
|
@ -259,24 +259,24 @@ typedef char * ( *switcher_get_completion )( const Switcher *sw, unsigned int se
|
||||||
*
|
*
|
||||||
* @returns 1 when it matches, 0 if not.
|
* @returns 1 when it matches, 0 if not.
|
||||||
*/
|
*/
|
||||||
typedef int ( *switcher_token_match )( const Switcher *data, char **tokens, int not_ascii, int case_sensitive, unsigned int index );
|
typedef int ( *switcher_token_match )( const Mode *data, char **tokens, int not_ascii, int case_sensitive, unsigned int index );
|
||||||
|
|
||||||
typedef void ( *switcher_init )( Switcher *sw );
|
typedef void ( *switcher_init )( Mode *sw );
|
||||||
|
|
||||||
typedef unsigned int ( *switcher_get_num_entries )( const Switcher *sw );
|
typedef unsigned int ( *switcher_get_num_entries )( const Mode *sw );
|
||||||
|
|
||||||
typedef void ( *switcher_destroy )( Switcher *sw );
|
typedef void ( *switcher_destroy )( Mode *sw );
|
||||||
|
|
||||||
typedef SwitcherMode ( *switcher_result )( Switcher *sw, int menu_retv, char **input, unsigned int selected_line );
|
typedef ModeMode ( *switcher_result )( Mode *sw, int menu_retv, char **input, unsigned int selected_line );
|
||||||
|
|
||||||
typedef int ( *switcher_is_not_ascii )( const Switcher *sw, unsigned int index );
|
typedef int ( *switcher_is_not_ascii )( const Mode *sw, unsigned int index );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Structure defining a switcher.
|
* Structure defining a switcher.
|
||||||
* It consists of a name, callback and if enabled
|
* It consists of a name, callback and if enabled
|
||||||
* a textbox for the sidebar-mode.
|
* a textbox for the sidebar-mode.
|
||||||
*/
|
*/
|
||||||
struct _Switcher
|
struct _Mode
|
||||||
{
|
{
|
||||||
// Name (max 31 char long)
|
// Name (max 31 char long)
|
||||||
char name[32];
|
char name[32];
|
||||||
|
@ -289,32 +289,32 @@ struct _Switcher
|
||||||
/**
|
/**
|
||||||
* A switcher normally consists of the following parts:
|
* A switcher normally consists of the following parts:
|
||||||
*/
|
*/
|
||||||
// Initialize the Switcher
|
// Initialize the Mode
|
||||||
switcher_init init;
|
switcher_init init;
|
||||||
// Destroy the switcher, e.g. free all its memory.
|
// Destroy the switcher, e.g. free all its memory.
|
||||||
switcher_destroy destroy;
|
switcher_destroy destroy;
|
||||||
// Get number of entries to display. (unfiltered).
|
// Get number of entries to display. (unfiltered).
|
||||||
switcher_get_num_entries get_num_entries;
|
switcher_get_num_entries get_num_entries;
|
||||||
// Check if the element is ascii.
|
// Check if the element is ascii.
|
||||||
switcher_is_not_ascii is_not_ascii;
|
switcher_is_not_ascii is_not_ascii;
|
||||||
// Process the result of the user selection.
|
// Process the result of the user selection.
|
||||||
switcher_result result;
|
switcher_result result;
|
||||||
// Token match.
|
// Token match.
|
||||||
switcher_token_match token_match;
|
switcher_token_match token_match;
|
||||||
// Get the string to display for the entry.
|
// Get the string to display for the entry.
|
||||||
switcher_get_display_value mgrv;
|
switcher_get_display_value mgrv;
|
||||||
// Get the 'completed' entry.
|
// Get the 'completed' entry.
|
||||||
switcher_get_completion get_completion;
|
switcher_get_completion get_completion;
|
||||||
|
|
||||||
// Pointer to private data.
|
// Pointer to private data.
|
||||||
void *private_data;
|
void *private_data;
|
||||||
|
|
||||||
// Free SWitcher
|
// Free SWitcher
|
||||||
// Only to be used when the switcher object itself is dynamic.
|
// Only to be used when the switcher object itself is dynamic.
|
||||||
// And has data in `ed`
|
// And has data in `ed`
|
||||||
switcher_free free;
|
switcher_free free;
|
||||||
// Extra fields for script
|
// Extra fields for script
|
||||||
void *ed;
|
void *ed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define color_reset "\033[0m"
|
#define color_reset "\033[0m"
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include <dialogs/dialogs.h>
|
#include <dialogs/dialogs.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combi Switcher
|
* Combi Mode
|
||||||
*/
|
*/
|
||||||
typedef struct _CombiModePrivateData
|
typedef struct _CombiModePrivateData
|
||||||
{
|
{
|
||||||
|
@ -43,10 +43,10 @@ typedef struct _CombiModePrivateData
|
||||||
unsigned int *lengths;
|
unsigned int *lengths;
|
||||||
// List of switchers to combine.
|
// List of switchers to combine.
|
||||||
unsigned int num_switchers;
|
unsigned int num_switchers;
|
||||||
Switcher **switchers;
|
Mode **switchers;
|
||||||
} CombiModePrivateData;
|
} CombiModePrivateData;
|
||||||
|
|
||||||
static void combi_mode_parse_switchers ( Switcher *sw )
|
static void combi_mode_parse_switchers ( Mode *sw )
|
||||||
{
|
{
|
||||||
CombiModePrivateData *pd = sw->private_data;
|
CombiModePrivateData *pd = sw->private_data;
|
||||||
char *savept = NULL;
|
char *savept = NULL;
|
||||||
|
@ -56,8 +56,8 @@ static void combi_mode_parse_switchers ( Switcher *sw )
|
||||||
for ( char *token = strtok_r ( switcher_str, ",", &savept ); token != NULL;
|
for ( char *token = strtok_r ( switcher_str, ",", &savept ); token != NULL;
|
||||||
token = strtok_r ( NULL, ",", &savept ) ) {
|
token = strtok_r ( NULL, ",", &savept ) ) {
|
||||||
// Resize and add entry.
|
// Resize and add entry.
|
||||||
pd->switchers = (Switcher * *) g_realloc ( pd->switchers,
|
pd->switchers = (Mode * *) g_realloc ( pd->switchers,
|
||||||
sizeof ( Switcher* ) * ( pd->num_switchers + 1 ) );
|
sizeof ( Mode* ) * ( pd->num_switchers + 1 ) );
|
||||||
|
|
||||||
// Window switcher.
|
// Window switcher.
|
||||||
#ifdef WINDOW_MODE
|
#ifdef WINDOW_MODE
|
||||||
|
@ -82,7 +82,7 @@ static void combi_mode_parse_switchers ( Switcher *sw )
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// If not build in, use custom switchers.
|
// If not build in, use custom switchers.
|
||||||
Switcher *sw = script_switcher_parse_setup ( token );
|
Mode *sw = script_switcher_parse_setup ( token );
|
||||||
if ( sw != NULL ) {
|
if ( sw != NULL ) {
|
||||||
pd->switchers[pd->num_switchers++] = sw;
|
pd->switchers[pd->num_switchers++] = sw;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ static void combi_mode_parse_switchers ( Switcher *sw )
|
||||||
g_free ( switcher_str );
|
g_free ( switcher_str );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void combi_mode_init ( Switcher *sw )
|
static void combi_mode_init ( Mode *sw )
|
||||||
{
|
{
|
||||||
if ( sw->private_data == NULL ) {
|
if ( sw->private_data == NULL ) {
|
||||||
CombiModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
CombiModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
||||||
|
@ -120,12 +120,12 @@ static void combi_mode_init ( Switcher *sw )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static unsigned int combi_mode_get_num_entries ( const Switcher *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 *) sw->private_data;
|
||||||
return pd->cmd_list_length;
|
return pd->cmd_list_length;
|
||||||
}
|
}
|
||||||
static void combi_mode_destroy ( Switcher *sw )
|
static void combi_mode_destroy ( Mode *sw )
|
||||||
{
|
{
|
||||||
CombiModePrivateData *pd = (CombiModePrivateData *) sw->private_data;
|
CombiModePrivateData *pd = (CombiModePrivateData *) sw->private_data;
|
||||||
if ( pd != NULL ) {
|
if ( pd != NULL ) {
|
||||||
|
@ -140,7 +140,7 @@ static void combi_mode_destroy ( Switcher *sw )
|
||||||
sw->private_data = NULL;
|
sw->private_data = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static SwitcherMode combi_mode_result ( Switcher *sw, int mretv, char **input, unsigned int selected_line )
|
static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
|
||||||
{
|
{
|
||||||
CombiModePrivateData *pd = sw->private_data;
|
CombiModePrivateData *pd = sw->private_data;
|
||||||
if ( *input[0] == '!' ) {
|
if ( *input[0] == '!' ) {
|
||||||
|
@ -170,7 +170,7 @@ static SwitcherMode combi_mode_result ( Switcher *sw, int mretv, char **input, u
|
||||||
}
|
}
|
||||||
return MODE_EXIT;
|
return MODE_EXIT;
|
||||||
}
|
}
|
||||||
static int combi_mode_match ( const Switcher *sw, char **tokens, int not_ascii,
|
static int combi_mode_match ( const Mode *sw, char **tokens, int not_ascii,
|
||||||
int case_sensitive, unsigned int index )
|
int case_sensitive, unsigned int index )
|
||||||
{
|
{
|
||||||
CombiModePrivateData *pd = sw->private_data;
|
CombiModePrivateData *pd = sw->private_data;
|
||||||
|
@ -203,7 +203,7 @@ static int combi_mode_match ( const Switcher *sw, char **tokens, int not_ascii,
|
||||||
abort ();
|
abort ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static char * combi_mgrv ( const Switcher *sw, unsigned int selected_line, int *state, int get_entry )
|
static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *state, int get_entry )
|
||||||
{
|
{
|
||||||
CombiModePrivateData *pd = sw->private_data;
|
CombiModePrivateData *pd = sw->private_data;
|
||||||
if ( !get_entry ) {
|
if ( !get_entry ) {
|
||||||
|
@ -226,7 +226,7 @@ static char * combi_mgrv ( const Switcher *sw, unsigned int selected_line, int *
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
static int combi_is_not_ascii ( const Switcher *sw, unsigned int index )
|
static int combi_is_not_ascii ( const Mode *sw, unsigned int index )
|
||||||
{
|
{
|
||||||
CombiModePrivateData *pd = sw->private_data;
|
CombiModePrivateData *pd = sw->private_data;
|
||||||
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
|
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
|
||||||
|
@ -236,7 +236,7 @@ static int combi_is_not_ascii ( const Switcher *sw, unsigned int index )
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
static char * combi_get_completion ( const Switcher *sw, unsigned int index )
|
static char * combi_get_completion ( const Mode *sw, unsigned int index )
|
||||||
{
|
{
|
||||||
CombiModePrivateData *pd = sw->private_data;
|
CombiModePrivateData *pd = sw->private_data;
|
||||||
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
|
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
|
||||||
|
@ -257,7 +257,7 @@ static char * combi_get_completion ( const Switcher *sw, unsigned int index )
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Switcher combi_mode =
|
Mode combi_mode =
|
||||||
{
|
{
|
||||||
.name = "combi",
|
.name = "combi",
|
||||||
.keycfg = NULL,
|
.keycfg = NULL,
|
||||||
|
|
|
@ -64,7 +64,7 @@ typedef struct _DmenuModePrivateData
|
||||||
static char **get_dmenu ( unsigned int *length )
|
static char **get_dmenu ( unsigned int *length )
|
||||||
{
|
{
|
||||||
TICK_N ( "Read stdin START" );
|
TICK_N ( "Read stdin START" );
|
||||||
char **retv = NULL;
|
char **retv = NULL;
|
||||||
unsigned int rvlength = 1;
|
unsigned int rvlength = 1;
|
||||||
|
|
||||||
*length = 0;
|
*length = 0;
|
||||||
|
@ -96,7 +96,7 @@ static char **get_dmenu ( unsigned int *length )
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int dmenu_mode_get_num_entries ( const Switcher *sw )
|
static unsigned int dmenu_mode_get_num_entries ( const Mode *sw )
|
||||||
{
|
{
|
||||||
const DmenuModePrivateData *rmpd = (const DmenuModePrivateData *) sw->private_data;
|
const DmenuModePrivateData *rmpd = (const DmenuModePrivateData *) sw->private_data;
|
||||||
return rmpd->cmd_list_length;
|
return rmpd->cmd_list_length;
|
||||||
|
@ -137,9 +137,9 @@ static void parse_ranges ( char *input, struct range_pair **list, unsigned int *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *get_display_data ( const Switcher *data, unsigned int index, int *state, int get_entry )
|
static char *get_display_data ( const Mode *data, unsigned int index, int *state, int get_entry )
|
||||||
{
|
{
|
||||||
Switcher *sw = (Switcher *) data;
|
Mode *sw = (Mode *) data;
|
||||||
DmenuModePrivateData *pd = (DmenuModePrivateData *) sw->private_data;
|
DmenuModePrivateData *pd = (DmenuModePrivateData *) sw->private_data;
|
||||||
char **retv = (char * *) pd->cmd_list;
|
char **retv = (char * *) pd->cmd_list;
|
||||||
for ( unsigned int i = 0; i < pd->num_active_list; i++ ) {
|
for ( unsigned int i = 0; i < pd->num_active_list; i++ ) {
|
||||||
|
@ -206,7 +206,7 @@ static void dmenu_output_formatted_line ( const char *format, const char *string
|
||||||
fputc ( '\n', stdout );
|
fputc ( '\n', stdout );
|
||||||
fflush ( stdout );
|
fflush ( stdout );
|
||||||
}
|
}
|
||||||
static void dmenu_mode_free ( Switcher *sw )
|
static void dmenu_mode_free ( Mode *sw )
|
||||||
{
|
{
|
||||||
if ( sw->private_data == NULL ) {
|
if ( sw->private_data == NULL ) {
|
||||||
return;
|
return;
|
||||||
|
@ -227,7 +227,7 @@ static void dmenu_mode_free ( Switcher *sw )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dmenu_mode_init ( Switcher *sw )
|
static void dmenu_mode_init ( Mode *sw )
|
||||||
{
|
{
|
||||||
if ( sw->private_data != NULL ) {
|
if ( sw->private_data != NULL ) {
|
||||||
return;
|
return;
|
||||||
|
@ -279,19 +279,19 @@ static void dmenu_mode_init ( Switcher *sw )
|
||||||
pd->cmd_list = get_dmenu ( &( pd->cmd_list_length ) );
|
pd->cmd_list = get_dmenu ( &( pd->cmd_list_length ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dmenu_token_match ( const Switcher *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
|
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 *) sw->private_data;
|
||||||
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );
|
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dmenu_is_not_ascii ( const Switcher *sw, unsigned int index )
|
static int dmenu_is_not_ascii ( const Mode *sw, unsigned int index )
|
||||||
{
|
{
|
||||||
DmenuModePrivateData *rmpd = (DmenuModePrivateData *) sw->private_data;
|
DmenuModePrivateData *rmpd = (DmenuModePrivateData *) sw->private_data;
|
||||||
return is_not_ascii ( rmpd->cmd_list[index] );
|
return is_not_ascii ( rmpd->cmd_list[index] );
|
||||||
}
|
}
|
||||||
|
|
||||||
Switcher dmenu_mode =
|
Mode dmenu_mode =
|
||||||
{
|
{
|
||||||
.name = "dmenu",
|
.name = "dmenu",
|
||||||
.keycfg = NULL,
|
.keycfg = NULL,
|
||||||
|
|
|
@ -226,7 +226,7 @@ static void get_apps ( DRunModePrivateData *pd )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drun_mode_init ( Switcher *sw )
|
static void drun_mode_init ( Mode *sw )
|
||||||
{
|
{
|
||||||
if ( sw->private_data == NULL ) {
|
if ( sw->private_data == NULL ) {
|
||||||
DRunModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
DRunModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
||||||
|
@ -235,10 +235,10 @@ static void drun_mode_init ( Switcher *sw )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SwitcherMode drun_mode_result ( Switcher *sw, int mretv, char **input, unsigned int selected_line )
|
static ModeMode drun_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
|
||||||
{
|
{
|
||||||
DRunModePrivateData *rmpd = (DRunModePrivateData *) sw->private_data;
|
DRunModePrivateData *rmpd = (DRunModePrivateData *) sw->private_data;
|
||||||
SwitcherMode retv = MODE_EXIT;
|
ModeMode retv = MODE_EXIT;
|
||||||
|
|
||||||
int shift = ( ( mretv & MENU_SHIFT ) == MENU_SHIFT );
|
int shift = ( ( mretv & MENU_SHIFT ) == MENU_SHIFT );
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ static SwitcherMode drun_mode_result ( Switcher *sw, int mretv, char **input, un
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drun_mode_destroy ( Switcher *sw )
|
static void drun_mode_destroy ( Mode *sw )
|
||||||
{
|
{
|
||||||
DRunModePrivateData *rmpd = (DRunModePrivateData *) sw->private_data;
|
DRunModePrivateData *rmpd = (DRunModePrivateData *) sw->private_data;
|
||||||
if ( rmpd != NULL ) {
|
if ( rmpd != NULL ) {
|
||||||
|
@ -275,7 +275,7 @@ static void drun_mode_destroy ( Switcher *sw )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *mgrv ( const Switcher *sw, unsigned int selected_line, int *state, int get_entry )
|
static char *mgrv ( const Mode *sw, unsigned int selected_line, int *state, int get_entry )
|
||||||
{
|
{
|
||||||
DRunModePrivateData *pd = (DRunModePrivateData *) sw->private_data;
|
DRunModePrivateData *pd = (DRunModePrivateData *) sw->private_data;
|
||||||
*state |= MARKUP;
|
*state |= MARKUP;
|
||||||
|
@ -296,7 +296,7 @@ static char *mgrv ( const Switcher *sw, unsigned int selected_line, int *state,
|
||||||
dr->generic_name );
|
dr->generic_name );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static char *drun_get_completion ( const Switcher *sw, unsigned int index )
|
static char *drun_get_completion ( const Mode *sw, unsigned int index )
|
||||||
{
|
{
|
||||||
DRunModePrivateData *pd = (DRunModePrivateData *) sw->private_data;
|
DRunModePrivateData *pd = (DRunModePrivateData *) sw->private_data;
|
||||||
/* Free temp storage. */
|
/* Free temp storage. */
|
||||||
|
@ -309,7 +309,7 @@ static char *drun_get_completion ( const Switcher *sw, unsigned int index )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int drun_token_match ( const Switcher *data,
|
static int drun_token_match ( const Mode *data,
|
||||||
char **tokens,
|
char **tokens,
|
||||||
int not_ascii,
|
int not_ascii,
|
||||||
int case_sensitive,
|
int case_sensitive,
|
||||||
|
@ -329,12 +329,12 @@ static int drun_token_match ( const Switcher *data,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int drun_mode_get_num_entries ( const Switcher *sw )
|
static unsigned int drun_mode_get_num_entries ( const Mode *sw )
|
||||||
{
|
{
|
||||||
const DRunModePrivateData *pd = (const DRunModePrivateData *) sw->private_data;
|
const DRunModePrivateData *pd = (const DRunModePrivateData *) sw->private_data;
|
||||||
return pd->cmd_list_length;
|
return pd->cmd_list_length;
|
||||||
}
|
}
|
||||||
static int drun_is_not_ascii ( const Switcher *sw, unsigned int index )
|
static int drun_is_not_ascii ( const Mode *sw, unsigned int index )
|
||||||
{
|
{
|
||||||
DRunModePrivateData *pd = (DRunModePrivateData *) sw->private_data;
|
DRunModePrivateData *pd = (DRunModePrivateData *) sw->private_data;
|
||||||
if ( pd->entry_list[index].generic_name ) {
|
if ( pd->entry_list[index].generic_name ) {
|
||||||
|
@ -343,7 +343,7 @@ static int drun_is_not_ascii ( const Switcher *sw, unsigned int index )
|
||||||
return is_not_ascii ( pd->entry_list[index].name );
|
return is_not_ascii ( pd->entry_list[index].name );
|
||||||
}
|
}
|
||||||
|
|
||||||
Switcher drun_mode =
|
Mode drun_mode =
|
||||||
{
|
{
|
||||||
.name = "drun",
|
.name = "drun",
|
||||||
.keycfg = NULL,
|
.keycfg = NULL,
|
||||||
|
|
|
@ -267,7 +267,7 @@ typedef struct _RunModePrivateData
|
||||||
unsigned int cmd_list_length;
|
unsigned int cmd_list_length;
|
||||||
} RunModePrivateData;
|
} RunModePrivateData;
|
||||||
|
|
||||||
static void run_mode_init ( Switcher *sw )
|
static void run_mode_init ( Mode *sw )
|
||||||
{
|
{
|
||||||
if ( sw->private_data == NULL ) {
|
if ( sw->private_data == NULL ) {
|
||||||
RunModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
RunModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
||||||
|
@ -276,16 +276,16 @@ static void run_mode_init ( Switcher *sw )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int run_mode_get_num_entries ( const Switcher *sw )
|
static unsigned int run_mode_get_num_entries ( const Mode *sw )
|
||||||
{
|
{
|
||||||
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
|
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
|
||||||
return rmpd->cmd_list_length;
|
return rmpd->cmd_list_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SwitcherMode run_mode_result ( Switcher *sw, int mretv, char **input, unsigned int selected_line )
|
static ModeMode run_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
|
||||||
{
|
{
|
||||||
RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data;
|
RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data;
|
||||||
SwitcherMode retv = MODE_EXIT;
|
ModeMode retv = MODE_EXIT;
|
||||||
|
|
||||||
int shift = ( ( mretv & MENU_SHIFT ) == MENU_SHIFT );
|
int shift = ( ( mretv & MENU_SHIFT ) == MENU_SHIFT );
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ static SwitcherMode run_mode_result ( Switcher *sw, int mretv, char **input, uns
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void run_mode_destroy ( Switcher *sw )
|
static void run_mode_destroy ( Mode *sw )
|
||||||
{
|
{
|
||||||
RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data;
|
RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data;
|
||||||
if ( rmpd != NULL ) {
|
if ( rmpd != NULL ) {
|
||||||
|
@ -326,23 +326,23 @@ static void run_mode_destroy ( Switcher *sw )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *mgrv ( const Switcher *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, int get_entry )
|
static char *mgrv ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, int get_entry )
|
||||||
{
|
{
|
||||||
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
|
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
|
||||||
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
|
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
|
||||||
}
|
}
|
||||||
static int run_token_match ( const Switcher *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
|
static int run_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
|
||||||
{
|
{
|
||||||
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
|
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
|
||||||
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );
|
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run_is_not_ascii ( const Switcher *sw, unsigned int index )
|
static int run_is_not_ascii ( const Mode *sw, unsigned int index )
|
||||||
{
|
{
|
||||||
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
|
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
|
||||||
return is_not_ascii ( rmpd->cmd_list[index] );
|
return is_not_ascii ( rmpd->cmd_list[index] );
|
||||||
}
|
}
|
||||||
Switcher run_mode =
|
Mode run_mode =
|
||||||
{
|
{
|
||||||
.name = "run",
|
.name = "run",
|
||||||
.keycfg = NULL,
|
.keycfg = NULL,
|
||||||
|
|
|
@ -69,7 +69,7 @@ static char **get_script_output ( const char *command, unsigned int *length )
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char **execute_executor ( Switcher *sw, const char *result, unsigned int *length )
|
static char **execute_executor ( Mode *sw, const char *result, unsigned int *length )
|
||||||
{
|
{
|
||||||
char **retv = NULL;
|
char **retv = NULL;
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ static char **execute_executor ( Switcher *sw, const char *result, unsigned int
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void script_switcher_free ( Switcher *sw )
|
static void script_switcher_free ( Mode *sw )
|
||||||
{
|
{
|
||||||
if ( sw == NULL ) {
|
if ( sw == NULL ) {
|
||||||
return;
|
return;
|
||||||
|
@ -97,7 +97,7 @@ typedef struct _ScriptModePrivateData
|
||||||
unsigned int cmd_list_length;
|
unsigned int cmd_list_length;
|
||||||
} ScriptModePrivateData;
|
} ScriptModePrivateData;
|
||||||
|
|
||||||
static void script_mode_init ( Switcher *sw )
|
static void script_mode_init ( Mode *sw )
|
||||||
{
|
{
|
||||||
if ( sw->private_data == NULL ) {
|
if ( sw->private_data == NULL ) {
|
||||||
ScriptModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
ScriptModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
||||||
|
@ -105,16 +105,16 @@ static void script_mode_init ( Switcher *sw )
|
||||||
pd->cmd_list = get_script_output ( (const char *) sw->ed, &( pd->cmd_list_length ) );
|
pd->cmd_list = get_script_output ( (const char *) sw->ed, &( pd->cmd_list_length ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static unsigned int script_mode_get_num_entries ( const Switcher *sw )
|
static unsigned int script_mode_get_num_entries ( const Mode *sw )
|
||||||
{
|
{
|
||||||
const ScriptModePrivateData *rmpd = (const ScriptModePrivateData *) sw->private_data;
|
const ScriptModePrivateData *rmpd = (const ScriptModePrivateData *) sw->private_data;
|
||||||
return rmpd->cmd_list_length;
|
return rmpd->cmd_list_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SwitcherMode script_mode_result ( Switcher *sw, int mretv, char **input, unsigned int selected_line )
|
static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
|
||||||
{
|
{
|
||||||
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
|
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
|
||||||
SwitcherMode retv = MODE_EXIT;
|
ModeMode retv = MODE_EXIT;
|
||||||
char **new_list = NULL;
|
char **new_list = NULL;
|
||||||
unsigned int new_length = 0;
|
unsigned int new_length = 0;
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ static SwitcherMode script_mode_result ( Switcher *sw, int mretv, char **input,
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void script_mode_destroy ( Switcher *sw )
|
static void script_mode_destroy ( Mode *sw )
|
||||||
{
|
{
|
||||||
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
|
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
|
||||||
if ( rmpd != NULL ) {
|
if ( rmpd != NULL ) {
|
||||||
|
@ -156,27 +156,27 @@ static void script_mode_destroy ( Switcher *sw )
|
||||||
sw->private_data = NULL;
|
sw->private_data = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static char *mgrv ( const Switcher *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, int get_entry )
|
static char *mgrv ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, int get_entry )
|
||||||
{
|
{
|
||||||
ScriptModePrivateData *rmpd = sw->private_data;
|
ScriptModePrivateData *rmpd = sw->private_data;
|
||||||
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
|
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int script_token_match ( const Switcher *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
|
static int script_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
|
||||||
{
|
{
|
||||||
ScriptModePrivateData *rmpd = sw->private_data;
|
ScriptModePrivateData *rmpd = sw->private_data;
|
||||||
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );
|
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int script_is_not_ascii ( const Switcher *sw, unsigned int index )
|
static int script_is_not_ascii ( const Mode *sw, unsigned int index )
|
||||||
{
|
{
|
||||||
ScriptModePrivateData *rmpd = sw->private_data;
|
ScriptModePrivateData *rmpd = sw->private_data;
|
||||||
return is_not_ascii ( rmpd->cmd_list[index] );
|
return is_not_ascii ( rmpd->cmd_list[index] );
|
||||||
}
|
}
|
||||||
|
|
||||||
Switcher *script_switcher_parse_setup ( const char *str )
|
Mode *script_switcher_parse_setup ( const char *str )
|
||||||
{
|
{
|
||||||
Switcher *sw = g_malloc0 ( sizeof ( *sw ) );
|
Mode *sw = g_malloc0 ( sizeof ( *sw ) );
|
||||||
char *endp = NULL;
|
char *endp = NULL;
|
||||||
char *parse = g_strdup ( str );
|
char *parse = g_strdup ( str );
|
||||||
unsigned int index = 0;
|
unsigned int index = 0;
|
||||||
|
|
|
@ -322,7 +322,7 @@ typedef struct _SSHModePrivateData
|
||||||
unsigned int cmd_list_length;
|
unsigned int cmd_list_length;
|
||||||
} SSHModePrivateData;
|
} SSHModePrivateData;
|
||||||
|
|
||||||
static void ssh_mode_init ( Switcher *sw )
|
static void ssh_mode_init ( Mode *sw )
|
||||||
{
|
{
|
||||||
if ( sw->private_data == NULL ) {
|
if ( sw->private_data == NULL ) {
|
||||||
SSHModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
SSHModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
||||||
|
@ -331,14 +331,14 @@ static void ssh_mode_init ( Switcher *sw )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int ssh_mode_get_num_entries ( const Switcher *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 *) sw->private_data;
|
||||||
return rmpd->cmd_list_length;
|
return rmpd->cmd_list_length;
|
||||||
}
|
}
|
||||||
static SwitcherMode ssh_mode_result ( Switcher *sw, int mretv, char **input, unsigned int selected_line )
|
static ModeMode ssh_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
|
||||||
{
|
{
|
||||||
SwitcherMode retv = MODE_EXIT;
|
ModeMode retv = MODE_EXIT;
|
||||||
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
|
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
|
||||||
if ( mretv & MENU_NEXT ) {
|
if ( mretv & MENU_NEXT ) {
|
||||||
retv = NEXT_DIALOG;
|
retv = NEXT_DIALOG;
|
||||||
|
@ -366,7 +366,7 @@ static SwitcherMode ssh_mode_result ( Switcher *sw, int mretv, char **input, uns
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ssh_mode_destroy ( Switcher *sw )
|
static void ssh_mode_destroy ( Mode *sw )
|
||||||
{
|
{
|
||||||
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
|
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
|
||||||
if ( rmpd != NULL ) {
|
if ( rmpd != NULL ) {
|
||||||
|
@ -376,24 +376,24 @@ static void ssh_mode_destroy ( Switcher *sw )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *mgrv ( const Switcher *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, int get_entry )
|
static char *mgrv ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, int get_entry )
|
||||||
{
|
{
|
||||||
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
|
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
|
||||||
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
|
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
|
||||||
}
|
}
|
||||||
static int ssh_token_match ( const Switcher *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
|
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 *) sw->private_data;
|
||||||
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );
|
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ssh_is_not_ascii ( const Switcher *sw, unsigned int index )
|
static int ssh_is_not_ascii ( const Mode *sw, unsigned int index )
|
||||||
{
|
{
|
||||||
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
|
SSHModePrivateData *rmpd = (SSHModePrivateData *) sw->private_data;
|
||||||
return is_not_ascii ( rmpd->cmd_list[index] );
|
return is_not_ascii ( rmpd->cmd_list[index] );
|
||||||
}
|
}
|
||||||
|
|
||||||
Switcher ssh_mode =
|
Mode ssh_mode =
|
||||||
{
|
{
|
||||||
.name = "ssh",
|
.name = "ssh",
|
||||||
.keycfg = NULL,
|
.keycfg = NULL,
|
||||||
|
|
|
@ -308,7 +308,7 @@ static client* window_client ( Display *display, Window win )
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct _SwitcherModePrivateData
|
typedef struct _ModeModePrivateData
|
||||||
{
|
{
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
char **cmd_list;
|
char **cmd_list;
|
||||||
|
@ -318,19 +318,19 @@ typedef struct _SwitcherModePrivateData
|
||||||
// Current window.
|
// Current window.
|
||||||
unsigned int index;
|
unsigned int index;
|
||||||
char *cache;
|
char *cache;
|
||||||
} SwitcherModePrivateData;
|
} ModeModePrivateData;
|
||||||
|
|
||||||
static int window_match ( const Switcher *sw, char **tokens,
|
static int window_match ( const Mode *sw, char **tokens,
|
||||||
__attribute__( ( unused ) ) int not_ascii,
|
__attribute__( ( unused ) ) int not_ascii,
|
||||||
int case_sensitive, unsigned int index )
|
int case_sensitive, unsigned int index )
|
||||||
{
|
{
|
||||||
SwitcherModePrivateData *rmpd = (SwitcherModePrivateData *) sw->private_data;
|
ModeModePrivateData *rmpd = (ModeModePrivateData *) sw->private_data;
|
||||||
int match = 1;
|
int match = 1;
|
||||||
const winlist *ids = ( winlist * ) rmpd->ids;
|
const winlist *ids = ( winlist * ) rmpd->ids;
|
||||||
// Want to pull directly out of cache, X calls are not thread safe.
|
// Want to pull directly out of cache, X calls are not thread safe.
|
||||||
int idx = winlist_find ( cache_client, ids->array[index] );
|
int idx = winlist_find ( cache_client, ids->array[index] );
|
||||||
g_assert ( idx >= 0 );
|
g_assert ( idx >= 0 );
|
||||||
client *c = cache_client->data[idx];
|
client *c = cache_client->data[idx];
|
||||||
|
|
||||||
if ( tokens ) {
|
if ( tokens ) {
|
||||||
for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) {
|
for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) {
|
||||||
|
@ -365,22 +365,22 @@ static int window_match ( const Switcher *sw, char **tokens,
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int window_mode_get_num_entries ( const Switcher *sw )
|
static unsigned int window_mode_get_num_entries ( const Mode *sw )
|
||||||
{
|
{
|
||||||
const SwitcherModePrivateData *pd = (const SwitcherModePrivateData *) sw->private_data;
|
const ModeModePrivateData *pd = (const ModeModePrivateData *) sw->private_data;
|
||||||
return pd->cmd_list_length;
|
return pd->cmd_list_length;
|
||||||
}
|
}
|
||||||
static void _window_mode_load_data ( Switcher *sw, unsigned int cd )
|
static void _window_mode_load_data ( Mode *sw, unsigned int cd )
|
||||||
{
|
{
|
||||||
SwitcherModePrivateData *pd = (SwitcherModePrivateData *) sw->private_data;
|
ModeModePrivateData *pd = (ModeModePrivateData *) sw->private_data;
|
||||||
Screen *screen = DefaultScreenOfDisplay ( display );
|
Screen *screen = DefaultScreenOfDisplay ( display );
|
||||||
Window root = RootWindow ( display, XScreenNumberOfScreen ( screen ) );
|
Window root = RootWindow ( display, XScreenNumberOfScreen ( screen ) );
|
||||||
// find window list
|
// find window list
|
||||||
Atom type;
|
Atom type;
|
||||||
int nwins = 0;
|
int nwins = 0;
|
||||||
Window wins[100];
|
Window wins[100];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
Window curr_win_id = 0;
|
Window curr_win_id = 0;
|
||||||
// Create cache
|
// Create cache
|
||||||
|
|
||||||
x11_cache_create ();
|
x11_cache_create ();
|
||||||
|
@ -494,27 +494,27 @@ static void _window_mode_load_data ( Switcher *sw, unsigned int cd )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void window_mode_init ( Switcher *sw )
|
static void window_mode_init ( Mode *sw )
|
||||||
{
|
{
|
||||||
if ( sw->private_data == NULL ) {
|
if ( sw->private_data == NULL ) {
|
||||||
SwitcherModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
ModeModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
||||||
sw->private_data = (void *) pd;
|
sw->private_data = (void *) pd;
|
||||||
_window_mode_load_data ( sw, FALSE );
|
_window_mode_load_data ( sw, FALSE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void window_mode_init_cd ( Switcher *sw )
|
static void window_mode_init_cd ( Mode *sw )
|
||||||
{
|
{
|
||||||
if ( sw->private_data == NULL ) {
|
if ( sw->private_data == NULL ) {
|
||||||
SwitcherModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
ModeModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
||||||
sw->private_data = (void *) pd;
|
sw->private_data = (void *) pd;
|
||||||
_window_mode_load_data ( sw, TRUE );
|
_window_mode_load_data ( sw, TRUE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static SwitcherMode window_mode_result ( Switcher *sw, int mretv, G_GNUC_UNUSED char **input,
|
static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **input,
|
||||||
unsigned int selected_line )
|
unsigned int selected_line )
|
||||||
{
|
{
|
||||||
SwitcherModePrivateData *rmpd = (SwitcherModePrivateData *) sw->private_data;
|
ModeModePrivateData *rmpd = (ModeModePrivateData *) sw->private_data;
|
||||||
SwitcherMode retv = MODE_EXIT;
|
ModeMode retv = MODE_EXIT;
|
||||||
if ( mretv & MENU_NEXT ) {
|
if ( mretv & MENU_NEXT ) {
|
||||||
retv = NEXT_DIALOG;
|
retv = NEXT_DIALOG;
|
||||||
}
|
}
|
||||||
|
@ -545,9 +545,9 @@ static SwitcherMode window_mode_result ( Switcher *sw, int mretv, G_GNUC_UNUSED
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_mode_destroy ( Switcher *sw )
|
static void window_mode_destroy ( Mode *sw )
|
||||||
{
|
{
|
||||||
SwitcherModePrivateData *rmpd = (SwitcherModePrivateData *) sw->private_data;
|
ModeModePrivateData *rmpd = (ModeModePrivateData *) sw->private_data;
|
||||||
if ( rmpd != NULL ) {
|
if ( rmpd != NULL ) {
|
||||||
g_strfreev ( rmpd->cmd_list );
|
g_strfreev ( rmpd->cmd_list );
|
||||||
winlist_free ( rmpd->ids );
|
winlist_free ( rmpd->ids );
|
||||||
|
@ -559,9 +559,9 @@ static void window_mode_destroy ( Switcher *sw )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *mgrv ( const Switcher *sw, unsigned int selected_line, int *state, int get_entry )
|
static char *mgrv ( const Mode *sw, unsigned int selected_line, int *state, int get_entry )
|
||||||
{
|
{
|
||||||
SwitcherModePrivateData *rmpd = sw->private_data;
|
ModeModePrivateData *rmpd = sw->private_data;
|
||||||
if ( window_client ( display, rmpd->ids->array[selected_line] )->demands ) {
|
if ( window_client ( display, rmpd->ids->array[selected_line] )->demands ) {
|
||||||
*state |= URGENT;
|
*state |= URGENT;
|
||||||
}
|
}
|
||||||
|
@ -571,18 +571,18 @@ static char *mgrv ( const Switcher *sw, unsigned int selected_line, int *state,
|
||||||
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
|
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int window_is_not_ascii ( const Switcher *sw, unsigned int index )
|
static int window_is_not_ascii ( const Mode *sw, unsigned int index )
|
||||||
{
|
{
|
||||||
const SwitcherModePrivateData *rmpd = sw->private_data;
|
const ModeModePrivateData *rmpd = sw->private_data;
|
||||||
const winlist *ids = ( winlist * ) rmpd->ids;
|
const winlist *ids = ( winlist * ) rmpd->ids;
|
||||||
// Want to pull directly out of cache, X calls are not thread safe.
|
// Want to pull directly out of cache, X calls are not thread safe.
|
||||||
int idx = winlist_find ( cache_client, ids->array[index] );
|
int idx = winlist_find ( cache_client, ids->array[index] );
|
||||||
g_assert ( idx >= 0 );
|
g_assert ( idx >= 0 );
|
||||||
client *c = cache_client->data[idx];
|
client *c = cache_client->data[idx];
|
||||||
return is_not_ascii ( c->role ) || is_not_ascii ( c->class ) || is_not_ascii ( c->title ) || is_not_ascii ( c->name );
|
return is_not_ascii ( c->role ) || is_not_ascii ( c->class ) || is_not_ascii ( c->title ) || is_not_ascii ( c->name );
|
||||||
}
|
}
|
||||||
|
|
||||||
Switcher window_mode =
|
Mode window_mode =
|
||||||
{
|
{
|
||||||
.name = "window",
|
.name = "window",
|
||||||
.keycfg = NULL,
|
.keycfg = NULL,
|
||||||
|
@ -599,7 +599,7 @@ Switcher window_mode =
|
||||||
.private_data = NULL,
|
.private_data = NULL,
|
||||||
.free = NULL
|
.free = NULL
|
||||||
};
|
};
|
||||||
Switcher window_mode_cd =
|
Mode window_mode_cd =
|
||||||
{
|
{
|
||||||
.name = "windowcd",
|
.name = "windowcd",
|
||||||
.keycfg = NULL,
|
.keycfg = NULL,
|
||||||
|
|
196
source/rofi.c
196
source/rofi.c
|
@ -59,18 +59,18 @@
|
||||||
#include "xrmoptions.h"
|
#include "xrmoptions.h"
|
||||||
#include "dialogs/dialogs.h"
|
#include "dialogs/dialogs.h"
|
||||||
|
|
||||||
SwitcherMode switcher_run ( char **input, Switcher *sw );
|
ModeMode switcher_run ( char **input, Mode *sw );
|
||||||
|
|
||||||
typedef enum _MainLoopEvent
|
typedef enum _MainLoopEvent
|
||||||
{
|
{
|
||||||
ML_XEVENT,
|
ML_XEVENT,
|
||||||
ML_TIMEOUT
|
ML_TIMEOUT
|
||||||
} MainLoopEvent;
|
} MainLoopEvent;
|
||||||
typedef struct _Mode
|
typedef struct _ModeHolder
|
||||||
{
|
{
|
||||||
Switcher *sw;
|
Mode *sw;
|
||||||
textbox *tb;
|
textbox *tb;
|
||||||
} Mode;
|
} ModeHolder;
|
||||||
|
|
||||||
// Pidfile.
|
// Pidfile.
|
||||||
extern Atom netatoms[NUM_NETATOMS];
|
extern Atom netatoms[NUM_NETATOMS];
|
||||||
|
@ -83,9 +83,9 @@ char *display_str = NULL;
|
||||||
Window main_window = None;
|
Window main_window = None;
|
||||||
Colormap map = None;
|
Colormap map = None;
|
||||||
unsigned int normal_window_mode = FALSE;
|
unsigned int normal_window_mode = FALSE;
|
||||||
// Array of switchers.
|
// Array of modi.
|
||||||
Mode *switchers = NULL;
|
ModeHolder *modi = NULL;
|
||||||
unsigned int num_switchers = 0;
|
unsigned int num_modi = 0;
|
||||||
// Current selected switcher.
|
// Current selected switcher.
|
||||||
unsigned int curr_switcher = 0;
|
unsigned int curr_switcher = 0;
|
||||||
XVisualInfo vinfo;
|
XVisualInfo vinfo;
|
||||||
|
@ -102,12 +102,12 @@ GThreadPool *tpool = NULL;
|
||||||
*
|
*
|
||||||
* Find the index of the switcher with name.
|
* Find the index of the switcher with name.
|
||||||
*
|
*
|
||||||
* @returns index of the switcher in switchers, -1 if not found.
|
* @returns index of the switcher in modi, -1 if not found.
|
||||||
*/
|
*/
|
||||||
static int switcher_get ( const char *name )
|
static int switcher_get ( const char *name )
|
||||||
{
|
{
|
||||||
for ( unsigned int i = 0; i < num_switchers; i++ ) {
|
for ( unsigned int i = 0; i < num_modi; i++ ) {
|
||||||
if ( strcmp ( switchers[i].sw->name, name ) == 0 ) {
|
if ( strcmp ( modi[i].sw->name, name ) == 0 ) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ static int levenshtein ( const char *s1, const char *s2 )
|
||||||
|
|
||||||
typedef struct MenuState
|
typedef struct MenuState
|
||||||
{
|
{
|
||||||
Switcher *sw;
|
Mode *sw;
|
||||||
unsigned int menu_lines;
|
unsigned int menu_lines;
|
||||||
unsigned int max_elements;
|
unsigned int max_elements;
|
||||||
unsigned int max_rows;
|
unsigned int max_rows;
|
||||||
|
@ -551,7 +551,7 @@ inline static void menu_nav_last ( MenuState * state )
|
||||||
* @param key the Key to match
|
* @param key the Key to match
|
||||||
* @param modstate the modifier state to match
|
* @param modstate the modifier state to match
|
||||||
*
|
*
|
||||||
* Match key and modifier state against switchers.
|
* Match key and modifier state against modi.
|
||||||
*
|
*
|
||||||
* @return the index of the switcher that matches the key combination
|
* @return the index of the switcher that matches the key combination
|
||||||
* specified by key and modstate. Returns -1 if none was found
|
* specified by key and modstate. Returns -1 if none was found
|
||||||
|
@ -561,10 +561,10 @@ static int locate_switcher ( KeySym key, unsigned int modstate )
|
||||||
{
|
{
|
||||||
// ignore annoying modifiers
|
// ignore annoying modifiers
|
||||||
unsigned int modstate_filtered = modstate & ~( LockMask | NumlockMask );
|
unsigned int modstate_filtered = modstate & ~( LockMask | NumlockMask );
|
||||||
for ( unsigned int i = 0; i < num_switchers; i++ ) {
|
for ( unsigned int i = 0; i < num_modi; i++ ) {
|
||||||
if ( switchers[i].sw->keystr != NULL ) {
|
if ( modi[i].sw->keystr != NULL ) {
|
||||||
if ( ( modstate_filtered == switchers[i].sw->modmask ) &&
|
if ( ( modstate_filtered == modi[i].sw->modmask ) &&
|
||||||
switchers[i].sw->keysym == key ) {
|
modi[i].sw->keysym == key ) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -712,8 +712,8 @@ static void menu_mouse_navigation ( MenuState *state, XButtonEvent *xbe )
|
||||||
state->update = TRUE;
|
state->update = TRUE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for ( unsigned int i = 0; config.sidebar_mode == TRUE && i < num_switchers; i++ ) {
|
for ( unsigned int i = 0; config.sidebar_mode == TRUE && i < num_modi; i++ ) {
|
||||||
if ( intersect ( switchers[i].tb, xbe->x, xbe->y ) ) {
|
if ( intersect ( modi[i].tb, xbe->x, xbe->y ) ) {
|
||||||
*( state->selected_line ) = 0;
|
*( state->selected_line ) = 0;
|
||||||
state->retv = MENU_QUICK_SWITCH | ( i & MENU_LOWER_MASK );
|
state->retv = MENU_QUICK_SWITCH | ( i & MENU_LOWER_MASK );
|
||||||
state->quit = TRUE;
|
state->quit = TRUE;
|
||||||
|
@ -970,7 +970,7 @@ static void menu_update ( MenuState *state )
|
||||||
{
|
{
|
||||||
TICK ();
|
TICK ();
|
||||||
cairo_surface_t * surf = cairo_image_surface_create ( get_format (), state->w, state->h );
|
cairo_surface_t * surf = cairo_image_surface_create ( get_format (), state->w, state->h );
|
||||||
cairo_t *d = cairo_create ( surf );
|
cairo_t *d = cairo_create ( surf );
|
||||||
cairo_set_operator ( d, CAIRO_OPERATOR_SOURCE );
|
cairo_set_operator ( d, CAIRO_OPERATOR_SOURCE );
|
||||||
if ( config.fake_transparency ) {
|
if ( config.fake_transparency ) {
|
||||||
if ( state->bg != NULL ) {
|
if ( state->bg != NULL ) {
|
||||||
|
@ -1043,9 +1043,9 @@ static void menu_update ( MenuState *state )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( config.sidebar_mode == TRUE ) {
|
if ( config.sidebar_mode == TRUE ) {
|
||||||
for ( unsigned int j = 0; j < num_switchers; j++ ) {
|
for ( unsigned int j = 0; j < num_modi; j++ ) {
|
||||||
if ( switchers[j].tb != NULL ) {
|
if ( modi[j].tb != NULL ) {
|
||||||
textbox_draw ( switchers[j].tb, d );
|
textbox_draw ( modi[j].tb, d );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1096,12 +1096,12 @@ static void menu_resize ( MenuState *state )
|
||||||
unsigned int sbw = config.line_margin + 8;
|
unsigned int sbw = config.line_margin + 8;
|
||||||
scrollbar_move ( state->scrollbar, state->w - state->border - sbw, state->top_offset );
|
scrollbar_move ( state->scrollbar, state->w - state->border - sbw, state->top_offset );
|
||||||
if ( config.sidebar_mode == TRUE ) {
|
if ( config.sidebar_mode == TRUE ) {
|
||||||
int width = ( state->w - ( 2 * ( state->border ) + ( num_switchers - 1 ) * config.line_margin ) ) / num_switchers;
|
int width = ( state->w - ( 2 * ( state->border ) + ( num_modi - 1 ) * config.line_margin ) ) / num_modi;
|
||||||
for ( unsigned int j = 0; j < num_switchers; j++ ) {
|
for ( unsigned int j = 0; j < num_modi; j++ ) {
|
||||||
textbox_moveresize ( switchers[j].tb,
|
textbox_moveresize ( modi[j].tb,
|
||||||
state->border + j * ( width + config.line_margin ), state->h - state->line_height - state->border,
|
state->border + j * ( width + config.line_margin ), state->h - state->line_height - state->border,
|
||||||
width, state->line_height );
|
width, state->line_height );
|
||||||
textbox_draw ( switchers[j].tb, draw );
|
textbox_draw ( modi[j].tb, draw );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int entrybox_width = state->w - ( 2 * ( state->border ) ) - textbox_get_width ( state->prompt_tb )
|
int entrybox_width = state->w - ( 2 * ( state->border ) ) - textbox_get_width ( state->prompt_tb )
|
||||||
|
@ -1172,10 +1172,10 @@ static void menu_setup_fake_transparency ( Display *display, MenuState *state )
|
||||||
TICK_N ( "Fake transparency" );
|
TICK_N ( "Fake transparency" );
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *selected_line, unsigned int *next_pos, const char *message )
|
MenuReturn menu ( Mode *sw, char **input, char *prompt, unsigned int *selected_line, unsigned int *next_pos, const char *message )
|
||||||
{
|
{
|
||||||
TICK ();
|
TICK ();
|
||||||
int shift = FALSE;
|
int shift = FALSE;
|
||||||
MenuState state = {
|
MenuState state = {
|
||||||
.sw = sw,
|
.sw = sw,
|
||||||
.selected_line = selected_line,
|
.selected_line = selected_line,
|
||||||
|
@ -1362,11 +1362,11 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select
|
||||||
calculate_window_position ( &state );
|
calculate_window_position ( &state );
|
||||||
|
|
||||||
if ( config.sidebar_mode == TRUE ) {
|
if ( config.sidebar_mode == TRUE ) {
|
||||||
int width = ( state.w - ( 2 * ( state.border ) + ( num_switchers - 1 ) * config.line_margin ) ) / num_switchers;
|
int width = ( state.w - ( 2 * ( state.border ) + ( num_modi - 1 ) * config.line_margin ) ) / num_modi;
|
||||||
for ( unsigned int j = 0; j < num_switchers; j++ ) {
|
for ( unsigned int j = 0; j < num_modi; j++ ) {
|
||||||
switchers[j].tb = textbox_create ( TB_CENTER, state.border + j * ( width + config.line_margin ),
|
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,
|
state.h - state.line_height - state.border, width, state.line_height,
|
||||||
( j == curr_switcher ) ? HIGHLIGHT : NORMAL, switchers[j].sw->name );
|
( j == curr_switcher ) ? HIGHLIGHT : NORMAL, modi[j].sw->name );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1630,9 +1630,9 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select
|
||||||
// Free the switcher boxes.
|
// Free the switcher boxes.
|
||||||
// When state is free'ed we should no longer need these.
|
// When state is free'ed we should no longer need these.
|
||||||
if ( config.sidebar_mode == TRUE ) {
|
if ( config.sidebar_mode == TRUE ) {
|
||||||
for ( unsigned int j = 0; j < num_switchers; j++ ) {
|
for ( unsigned int j = 0; j < num_modi; j++ ) {
|
||||||
textbox_free ( switchers[j].tb );
|
textbox_free ( modi[j].tb );
|
||||||
switchers[j].tb = NULL;
|
modi[j].tb = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1795,7 +1795,7 @@ static int run_dmenu ()
|
||||||
return ret_state;
|
return ret_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void run_switcher ( SwitcherMode mode )
|
static void run_switcher ( ModeMode mode )
|
||||||
{
|
{
|
||||||
int pfd = setup ();
|
int pfd = setup ();
|
||||||
if ( pfd < 0 ) {
|
if ( pfd < 0 ) {
|
||||||
|
@ -1803,39 +1803,39 @@ static void run_switcher ( SwitcherMode mode )
|
||||||
}
|
}
|
||||||
// Otherwise check if requested mode is enabled.
|
// Otherwise check if requested mode is enabled.
|
||||||
char *input = g_strdup ( config.filter );
|
char *input = g_strdup ( config.filter );
|
||||||
for ( unsigned int i = 0; i < num_switchers; i++ ) {
|
for ( unsigned int i = 0; i < num_modi; i++ ) {
|
||||||
switchers[i].sw->init ( switchers[i].sw );
|
modi[i].sw->init ( modi[i].sw );
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
SwitcherMode retv;
|
ModeMode retv;
|
||||||
|
|
||||||
curr_switcher = mode;
|
curr_switcher = mode;
|
||||||
retv = switcher_run ( &input, switchers[mode].sw );
|
retv = switcher_run ( &input, modi[mode].sw );
|
||||||
// Find next enabled
|
// Find next enabled
|
||||||
if ( retv == NEXT_DIALOG ) {
|
if ( retv == NEXT_DIALOG ) {
|
||||||
mode = ( mode + 1 ) % num_switchers;
|
mode = ( mode + 1 ) % num_modi;
|
||||||
}
|
}
|
||||||
else if ( retv == PREVIOUS_DIALOG ) {
|
else if ( retv == PREVIOUS_DIALOG ) {
|
||||||
if ( mode == 0 ) {
|
if ( mode == 0 ) {
|
||||||
mode = num_switchers - 1;
|
mode = num_modi - 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mode = ( mode - 1 ) % num_switchers;
|
mode = ( mode - 1 ) % num_modi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( retv == RELOAD_DIALOG ) {
|
else if ( retv == RELOAD_DIALOG ) {
|
||||||
// do nothing.
|
// do nothing.
|
||||||
}
|
}
|
||||||
else if ( retv < MODE_EXIT ) {
|
else if ( retv < MODE_EXIT ) {
|
||||||
mode = ( retv ) % num_switchers;
|
mode = ( retv ) % num_modi;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mode = retv;
|
mode = retv;
|
||||||
}
|
}
|
||||||
} while ( mode != MODE_EXIT );
|
} while ( mode != MODE_EXIT );
|
||||||
g_free ( input );
|
g_free ( input );
|
||||||
for ( unsigned int i = 0; i < num_switchers; i++ ) {
|
for ( unsigned int i = 0; i < num_modi; i++ ) {
|
||||||
switchers[i].sw->destroy ( switchers[i].sw );
|
modi[i].sw->destroy ( modi[i].sw );
|
||||||
}
|
}
|
||||||
// cleanup
|
// cleanup
|
||||||
teardown ( pfd );
|
teardown ( pfd );
|
||||||
|
@ -1941,18 +1941,18 @@ static void cleanup ()
|
||||||
|
|
||||||
// Cleaning up memory allocated by the Xresources file.
|
// Cleaning up memory allocated by the Xresources file.
|
||||||
config_xresource_free ();
|
config_xresource_free ();
|
||||||
for ( unsigned int i = 0; i < num_switchers; i++ ) {
|
for ( unsigned int i = 0; i < num_modi; i++ ) {
|
||||||
// Switcher keystr is free'ed when needed by config system.
|
// Mode keystr is free'ed when needed by config system.
|
||||||
if ( switchers[i].sw->keycfg != NULL ) {
|
if ( modi[i].sw->keycfg != NULL ) {
|
||||||
g_free ( switchers[i].sw->keycfg );
|
g_free ( modi[i].sw->keycfg );
|
||||||
switchers[i].sw->keycfg = NULL;
|
modi[i].sw->keycfg = NULL;
|
||||||
}
|
}
|
||||||
// only used for script dialog.
|
// only used for script dialog.
|
||||||
if ( switchers[i].sw->free != NULL ) {
|
if ( modi[i].sw->free != NULL ) {
|
||||||
switchers[i].sw->free ( switchers[i].sw );
|
modi[i].sw->free ( modi[i].sw );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_free ( switchers );
|
g_free ( modi );
|
||||||
|
|
||||||
// Cleanup the custom keybinding
|
// Cleanup the custom keybinding
|
||||||
cleanup_abe ();
|
cleanup_abe ();
|
||||||
|
@ -1961,60 +1961,60 @@ static void cleanup ()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the switcher string, into internal array of type Switcher.
|
* Parse the switcher string, into internal array of type Mode.
|
||||||
*
|
*
|
||||||
* String is split on separator ','
|
* String is split on separator ','
|
||||||
* First the three build-in modi are checked: window, run, ssh
|
* First the three build-in modi are checked: window, run, ssh
|
||||||
* if that fails, a script-switcher is created.
|
* if that fails, a script-switcher is created.
|
||||||
*/
|
*/
|
||||||
static void setup_switchers ( void )
|
static void setup_modi ( void )
|
||||||
{
|
{
|
||||||
char *savept = NULL;
|
char *savept = NULL;
|
||||||
// Make a copy, as strtok will modify it.
|
// Make a copy, as strtok will modify it.
|
||||||
char *switcher_str = g_strdup ( config.switchers );
|
char *switcher_str = g_strdup ( config.modi );
|
||||||
// Split token on ','. This modifies switcher_str.
|
// Split token on ','. This modifies switcher_str.
|
||||||
for ( char *token = strtok_r ( switcher_str, ",", &savept ); token != NULL; token = strtok_r ( NULL, ",", &savept ) ) {
|
for ( char *token = strtok_r ( switcher_str, ",", &savept ); token != NULL; token = strtok_r ( NULL, ",", &savept ) ) {
|
||||||
// Resize and add entry.
|
// Resize and add entry.
|
||||||
switchers = (Mode *) g_realloc ( switchers, sizeof ( Mode ) * ( num_switchers + 1 ) );
|
modi = (ModeHolder *) g_realloc ( modi, sizeof ( ModeHolder ) * ( num_modi + 1 ) );
|
||||||
switchers[num_switchers].tb = NULL;
|
modi[num_modi].tb = NULL;
|
||||||
|
|
||||||
// Window switcher.
|
// Window switcher.
|
||||||
#ifdef WINDOW_MODE
|
#ifdef WINDOW_MODE
|
||||||
if ( strcasecmp ( token, "window" ) == 0 ) {
|
if ( strcasecmp ( token, "window" ) == 0 ) {
|
||||||
switchers[num_switchers].sw = &window_mode;
|
modi[num_modi].sw = &window_mode;
|
||||||
num_switchers++;
|
num_modi++;
|
||||||
}
|
}
|
||||||
else if ( strcasecmp ( token, "windowcd" ) == 0 ) {
|
else if ( strcasecmp ( token, "windowcd" ) == 0 ) {
|
||||||
switchers[num_switchers].sw = &window_mode_cd;
|
modi[num_modi].sw = &window_mode_cd;
|
||||||
num_switchers++;
|
num_modi++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif // WINDOW_MODE
|
#endif // WINDOW_MODE
|
||||||
// SSh dialog
|
// SSh dialog
|
||||||
if ( strcasecmp ( token, "ssh" ) == 0 ) {
|
if ( strcasecmp ( token, "ssh" ) == 0 ) {
|
||||||
switchers[num_switchers].sw = &ssh_mode;
|
modi[num_modi].sw = &ssh_mode;
|
||||||
num_switchers++;
|
num_modi++;
|
||||||
}
|
}
|
||||||
// Run dialog
|
// Run dialog
|
||||||
else if ( strcasecmp ( token, "run" ) == 0 ) {
|
else if ( strcasecmp ( token, "run" ) == 0 ) {
|
||||||
switchers[num_switchers].sw = &run_mode;
|
modi[num_modi].sw = &run_mode;
|
||||||
num_switchers++;
|
num_modi++;
|
||||||
}
|
}
|
||||||
else if ( strcasecmp ( token, "drun" ) == 0 ) {
|
else if ( strcasecmp ( token, "drun" ) == 0 ) {
|
||||||
switchers[num_switchers].sw = &drun_mode;
|
modi[num_modi].sw = &drun_mode;
|
||||||
num_switchers++;
|
num_modi++;
|
||||||
}
|
}
|
||||||
// combi dialog
|
// combi dialog
|
||||||
else if ( strcasecmp ( token, "combi" ) == 0 ) {
|
else if ( strcasecmp ( token, "combi" ) == 0 ) {
|
||||||
switchers[num_switchers].sw = &combi_mode;
|
modi[num_modi].sw = &combi_mode;
|
||||||
num_switchers++;
|
num_modi++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// If not build in, use custom switchers.
|
// If not build in, use custom modi.
|
||||||
Switcher *sw = script_switcher_parse_setup ( token );
|
Mode *sw = script_switcher_parse_setup ( token );
|
||||||
if ( sw != NULL ) {
|
if ( sw != NULL ) {
|
||||||
switchers[num_switchers].sw = sw;
|
modi[num_modi].sw = sw;
|
||||||
num_switchers++;
|
num_modi++;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Report error, don't continue.
|
// Report error, don't continue.
|
||||||
|
@ -2028,9 +2028,9 @@ static void setup_switchers ( void )
|
||||||
g_free ( switcher_str );
|
g_free ( switcher_str );
|
||||||
// We cannot do this in main loop, as we create pointer to string,
|
// We cannot do this in main loop, as we create pointer to string,
|
||||||
// and re-alloc moves that pointer.
|
// and re-alloc moves that pointer.
|
||||||
for ( unsigned int i = 0; i < num_switchers; i++ ) {
|
for ( unsigned int i = 0; i < num_modi; i++ ) {
|
||||||
switchers[i].sw->keycfg = g_strdup_printf ( "key-%s", switchers[i].sw->name );
|
modi[i].sw->keycfg = g_strdup_printf ( "key-%s", modi[i].sw->name );
|
||||||
config_parser_add_option ( xrm_String, switchers[i].sw->keycfg, (void * *) &( switchers[i].sw->keystr ), "Keybinding" );
|
config_parser_add_option ( xrm_String, modi[i].sw->keycfg, (void * *) &( modi[i].sw->keystr ), "Keybinding" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2056,11 +2056,11 @@ static inline void load_configuration_dynamic ( Display *display )
|
||||||
|
|
||||||
static void release_global_keybindings ()
|
static void release_global_keybindings ()
|
||||||
{
|
{
|
||||||
for ( unsigned int i = 0; i < num_switchers; i++ ) {
|
for ( unsigned int i = 0; i < num_modi; i++ ) {
|
||||||
if ( switchers[i].sw->keystr != NULL ) {
|
if ( modi[i].sw->keystr != NULL ) {
|
||||||
// No need to parse key, this should be done when grabbing.
|
// No need to parse key, this should be done when grabbing.
|
||||||
if ( switchers[i].sw->keysym != NoSymbol ) {
|
if ( modi[i].sw->keysym != NoSymbol ) {
|
||||||
x11_ungrab_key ( display, switchers[i].sw->modmask, switchers[i].sw->keysym );
|
x11_ungrab_key ( display, modi[i].sw->modmask, modi[i].sw->keysym );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2068,11 +2068,11 @@ static void release_global_keybindings ()
|
||||||
static int grab_global_keybindings ()
|
static int grab_global_keybindings ()
|
||||||
{
|
{
|
||||||
int key_bound = FALSE;
|
int key_bound = FALSE;
|
||||||
for ( unsigned int i = 0; i < num_switchers; i++ ) {
|
for ( unsigned int i = 0; i < num_modi; i++ ) {
|
||||||
if ( switchers[i].sw->keystr != NULL ) {
|
if ( modi[i].sw->keystr != NULL ) {
|
||||||
x11_parse_key ( switchers[i].sw->keystr, &( switchers[i].sw->modmask ), &( switchers[i].sw->keysym ) );
|
x11_parse_key ( modi[i].sw->keystr, &( modi[i].sw->modmask ), &( modi[i].sw->keysym ) );
|
||||||
if ( switchers[i].sw->keysym != NoSymbol ) {
|
if ( modi[i].sw->keysym != NoSymbol ) {
|
||||||
x11_grab_key ( display, switchers[i].sw->modmask, switchers[i].sw->keysym );
|
x11_grab_key ( display, modi[i].sw->modmask, modi[i].sw->keysym );
|
||||||
key_bound = TRUE;
|
key_bound = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2082,12 +2082,12 @@ static int grab_global_keybindings ()
|
||||||
static void print_global_keybindings ()
|
static void print_global_keybindings ()
|
||||||
{
|
{
|
||||||
fprintf ( stdout, "listening to the following keys:\n" );
|
fprintf ( stdout, "listening to the following keys:\n" );
|
||||||
for ( unsigned int i = 0; i < num_switchers; i++ ) {
|
for ( unsigned int i = 0; i < num_modi; i++ ) {
|
||||||
if ( switchers[i].sw->keystr != NULL ) {
|
if ( modi[i].sw->keystr != NULL ) {
|
||||||
fprintf ( stdout, "\t* "color_bold "%s"color_reset " on %s\n", switchers[i].sw->name, switchers[i].sw->keystr );
|
fprintf ( stdout, "\t* "color_bold "%s"color_reset " on %s\n", modi[i].sw->name, modi[i].sw->keystr );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf ( stdout, "\t* "color_bold "%s"color_reset " on <unspecified>\n", switchers[i].sw->name );
|
fprintf ( stdout, "\t* "color_bold "%s"color_reset " on <unspecified>\n", modi[i].sw->name );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2233,7 +2233,7 @@ static int main_loop_signal_handler ( char command, int quiet )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitcherMode switcher_run ( char **input, Switcher *sw )
|
ModeMode switcher_run ( char **input, Mode *sw )
|
||||||
{
|
{
|
||||||
char *prompt = g_strdup_printf ( "%s:", sw->name );
|
char *prompt = g_strdup_printf ( "%s:", sw->name );
|
||||||
unsigned int selected_line = UINT32_MAX;
|
unsigned int selected_line = UINT32_MAX;
|
||||||
|
@ -2359,8 +2359,8 @@ int main ( int argc, char *argv[] )
|
||||||
load_configuration ( display );
|
load_configuration ( display );
|
||||||
}
|
}
|
||||||
if ( !dmenu_mode ) {
|
if ( !dmenu_mode ) {
|
||||||
// setup_switchers
|
// setup_modi
|
||||||
setup_switchers ();
|
setup_modi ();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Add dmenu options.
|
// Add dmenu options.
|
||||||
|
@ -2452,8 +2452,8 @@ int main ( int argc, char *argv[] )
|
||||||
fprintf ( stderr, "Rofi was launched in daemon mode, but no key-binding was specified.\n" );
|
fprintf ( stderr, "Rofi was launched in daemon mode, but no key-binding was specified.\n" );
|
||||||
fprintf ( stderr, "Please check the manpage on how to specify a key-binding.\n" );
|
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" );
|
fprintf ( stderr, "The following modi are enabled and keys can be specified:\n" );
|
||||||
for ( unsigned int i = 0; i < num_switchers; i++ ) {
|
for ( unsigned int i = 0; i < num_modi; i++ ) {
|
||||||
fprintf ( stderr, "\t* "color_bold "%s"color_reset ": -key-%s <key>\n", switchers[i].sw->name, switchers[i].sw->name );
|
fprintf ( stderr, "\t* "color_bold "%s"color_reset ": -key-%s <key>\n", modi[i].sw->name, modi[i].sw->name );
|
||||||
}
|
}
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,8 +55,8 @@ typedef struct
|
||||||
* Currently supports string, boolean and number (signed and unsigned).
|
* Currently supports string, boolean and number (signed and unsigned).
|
||||||
*/
|
*/
|
||||||
static XrmOption xrmOptions[] = {
|
static XrmOption xrmOptions[] = {
|
||||||
{ xrm_String, "switchers", { .str = &config.switchers }, NULL, "" },
|
{ xrm_String, "switchers", { .str = &config.modi }, NULL, "" },
|
||||||
{ xrm_String, "modi", { .str = &config.switchers }, NULL, "Enabled modi" },
|
{ xrm_String, "modi", { .str = &config.modi }, NULL, "Enabled modi" },
|
||||||
{ xrm_Number, "opacity", { .num = &config.window_opacity }, NULL, "Window opacity" },
|
{ xrm_Number, "opacity", { .num = &config.window_opacity }, NULL, "Window opacity" },
|
||||||
{ xrm_SNumber, "width", { .snum = &config.menu_width }, NULL, "Window width" },
|
{ xrm_SNumber, "width", { .snum = &config.menu_width }, NULL, "Window width" },
|
||||||
{ xrm_Number, "lines", { .num = &config.menu_lines }, NULL, "Number of lines" },
|
{ xrm_Number, "lines", { .num = &config.menu_lines }, NULL, "Number of lines" },
|
||||||
|
|
Loading…
Add table
Reference in a new issue