2014-01-20 22:36:20 +00:00
|
|
|
#ifndef __SIMPLESWITCHER_H__
|
|
|
|
#define __SIMPLESWITCHER_H__
|
2014-01-26 12:29:38 +00:00
|
|
|
#include <X11/X.h>
|
2014-08-07 19:42:16 +00:00
|
|
|
#include <glib.h>
|
2015-03-27 19:28:53 +00:00
|
|
|
#include <textbox.h>
|
2014-01-25 22:37:37 +00:00
|
|
|
|
2014-01-20 22:36:20 +00:00
|
|
|
|
2014-11-25 07:27:08 +00:00
|
|
|
/**
|
|
|
|
* Pointer to xdg cache directory.
|
|
|
|
*/
|
2014-01-25 22:37:37 +00:00
|
|
|
extern const char *cache_dir;
|
2014-01-20 22:36:20 +00:00
|
|
|
|
2015-03-27 19:28:53 +00:00
|
|
|
typedef struct _Switcher Switcher;
|
2014-06-02 10:54:35 +00:00
|
|
|
/**
|
|
|
|
* Enum used to sum the possible states of ROFI.
|
|
|
|
*/
|
2014-03-22 20:04:19 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2014-06-02 10:54:35 +00:00
|
|
|
/** Exit. */
|
2014-11-11 20:50:16 +00:00
|
|
|
MODE_EXIT = 1000,
|
2014-06-02 10:54:35 +00:00
|
|
|
/** Skip to the next cycle-able dialog. */
|
2014-11-11 20:50:16 +00:00
|
|
|
NEXT_DIALOG = 1001,
|
2014-07-21 19:39:24 +00:00
|
|
|
/** Reload current DIALOG */
|
2014-11-11 20:50:16 +00:00
|
|
|
RELOAD_DIALOG = 1002,
|
|
|
|
/** Previous dialog */
|
|
|
|
PREVIOUS_DIALOG = 1003
|
2014-01-20 22:36:20 +00:00
|
|
|
} SwitcherMode;
|
|
|
|
|
2014-11-25 07:27:08 +00:00
|
|
|
/**
|
|
|
|
* @param input Pointer to the user input.
|
|
|
|
* @param data Usr data.
|
|
|
|
*
|
|
|
|
* Callback typedef for a switcher
|
|
|
|
*
|
|
|
|
* @returns SwitcherMode
|
|
|
|
*/
|
2014-07-21 19:39:24 +00:00
|
|
|
typedef SwitcherMode ( *switcher_callback )( char **input, void *data );
|
2015-03-27 19:28:53 +00:00
|
|
|
typedef void ( *switcher_free )( Switcher *data );
|
2014-06-02 10:54:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* State returned by the rofi window.
|
|
|
|
*/
|
2014-03-22 20:04:19 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2014-06-02 10:54:35 +00:00
|
|
|
/** Entry is selected. */
|
2015-03-27 19:28:53 +00:00
|
|
|
MENU_OK = 0x1,
|
2014-06-02 10:54:35 +00:00
|
|
|
/** User canceled the operation. (e.g. pressed escape) */
|
2015-03-27 19:28:53 +00:00
|
|
|
MENU_CANCEL = 0x2,
|
2014-06-02 10:54:35 +00:00
|
|
|
/** User requested a mode switch */
|
2015-03-27 19:28:53 +00:00
|
|
|
MENU_NEXT = 0x4,
|
2014-06-02 10:54:35 +00:00
|
|
|
/** Custom (non-matched) input was entered. */
|
2015-03-27 19:28:53 +00:00
|
|
|
MENU_CUSTOM_INPUT = 0x8,
|
2014-06-02 10:54:35 +00:00
|
|
|
/** User wanted to delete entry from history. */
|
2015-03-27 19:28:53 +00:00
|
|
|
MENU_ENTRY_DELETE = 0x10,
|
2014-11-25 07:27:08 +00:00
|
|
|
/** User wants to jump to another switcher. */
|
2015-03-27 19:28:53 +00:00
|
|
|
MENU_QUICK_SWITCH = 0x20,
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Go to the previous menu. */
|
2015-03-27 19:28:53 +00:00
|
|
|
MENU_PREVIOUS = 0x40,
|
|
|
|
/** Modifiers */
|
|
|
|
MENU_SHIFT = 0x1000
|
2014-02-01 13:03:23 +00:00
|
|
|
} MenuReturn;
|
2014-01-20 22:36:20 +00:00
|
|
|
|
2014-01-26 11:59:10 +00:00
|
|
|
|
2014-06-02 10:54:35 +00:00
|
|
|
/**
|
2014-11-25 07:27:08 +00:00
|
|
|
* @param tokens List of (input) tokens to match.
|
2014-11-25 11:57:34 +00:00
|
|
|
* @param input The entry to match against.
|
2015-01-12 13:13:46 +00:00
|
|
|
* @param case_sensitive Whether case is significant.
|
2014-11-25 07:27:08 +00:00
|
|
|
* @param index The current selected index.
|
|
|
|
* @param data User data.
|
|
|
|
*
|
2014-06-02 10:54:35 +00:00
|
|
|
* Function prototype for the matching algorithm.
|
2014-11-25 07:27:08 +00:00
|
|
|
*
|
|
|
|
* @returns 1 when it matches, 0 if not.
|
2014-06-02 10:54:35 +00:00
|
|
|
*/
|
2015-03-27 19:28:53 +00:00
|
|
|
typedef int ( *menu_match_cb )( char **tokens, const char *input, int case_sensitive, int index, Switcher *data );
|
2014-06-02 10:54:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param lines An array of strings to display.
|
2014-07-20 10:29:27 +00:00
|
|
|
* @param num_lines Length of the array with strings to display.
|
2014-06-02 10:54:35 +00:00
|
|
|
* @param input A pointer to a string where the inputted data is placed.
|
|
|
|
* @param prompt The prompt to show.
|
|
|
|
* @param time The current time (used for window interaction.)
|
|
|
|
* @param shift pointer to integer that is set to the state of the shift key.
|
|
|
|
* @param mmc Menu menu match callback, used for matching user input.
|
|
|
|
* @param mmc_data data to pass to mmc.
|
|
|
|
* @param selected_line pointer to integer holding the selected line.
|
|
|
|
*
|
|
|
|
* Main menu callback.
|
|
|
|
*
|
|
|
|
* @returns The command issued (see MenuReturn)
|
|
|
|
*/
|
2014-07-20 10:29:27 +00:00
|
|
|
MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prompt,
|
2015-03-27 19:28:53 +00:00
|
|
|
Time *time,
|
2014-03-22 20:04:19 +00:00
|
|
|
menu_match_cb mmc, void *mmc_data,
|
2015-03-27 19:28:53 +00:00
|
|
|
int *selected_line, int sorting ) __attribute__ ( ( nonnull ( 1, 3, 4, 8 ) ) );
|
2014-11-25 07:27:08 +00:00
|
|
|
/**
|
|
|
|
* @param sig The caught signal
|
|
|
|
*
|
|
|
|
* Catch the exit signal generated by X.
|
|
|
|
*/
|
2014-03-22 20:04:19 +00:00
|
|
|
void catch_exit ( __attribute__( ( unused ) ) int sig );
|
|
|
|
|
2014-11-25 07:27:08 +00:00
|
|
|
/**
|
|
|
|
* Enumeration indicating location or gravity of window.
|
|
|
|
*
|
|
|
|
* WL_NORTH_WEST WL_NORTH WL_NORTH_EAST
|
|
|
|
*
|
|
|
|
* WL_EAST WL_CENTER WL_EAST
|
|
|
|
*
|
|
|
|
* WL_SOUTH_WEST WL_SOUTH WL_SOUTH_EAST
|
|
|
|
*
|
|
|
|
*/
|
2014-03-22 20:04:19 +00:00
|
|
|
typedef enum _WindowLocation
|
|
|
|
{
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Center */
|
2014-03-22 20:04:19 +00:00
|
|
|
WL_CENTER = 0,
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Left top corner. */
|
2014-03-22 20:04:19 +00:00
|
|
|
WL_NORTH_WEST = 1,
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Top middle */
|
2014-03-22 20:04:19 +00:00
|
|
|
WL_NORTH = 2,
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Top right */
|
2014-03-22 20:04:19 +00:00
|
|
|
WL_NORTH_EAST = 3,
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Middle right */
|
2014-03-22 20:04:19 +00:00
|
|
|
WL_EAST = 4,
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Bottom right */
|
2014-03-22 20:04:19 +00:00
|
|
|
WL_EAST_SOUTH = 5,
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Bottom middle */
|
2014-03-22 20:04:19 +00:00
|
|
|
WL_SOUTH = 6,
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Bottom left */
|
2014-03-22 20:04:19 +00:00
|
|
|
WL_SOUTH_WEST = 7,
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Middle left */
|
2014-03-22 20:04:19 +00:00
|
|
|
WL_WEST = 8
|
2014-01-25 23:27:57 +00:00
|
|
|
} WindowLocation;
|
|
|
|
|
2014-01-23 10:39:12 +00:00
|
|
|
/**
|
|
|
|
* Settings
|
|
|
|
*/
|
|
|
|
|
2014-03-22 20:04:19 +00:00
|
|
|
typedef struct _Settings
|
|
|
|
{
|
2014-11-25 07:27:08 +00:00
|
|
|
/** List of enabled switchers */
|
2014-07-21 19:39:24 +00:00
|
|
|
char *switchers;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Window settings */
|
2014-03-22 20:04:19 +00:00
|
|
|
unsigned int window_opacity;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Border width */
|
2014-03-22 20:04:19 +00:00
|
|
|
unsigned int menu_bw;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Width (0-100 in %, > 100 in pixels, < 0 in char width.) */
|
2014-08-11 18:21:29 +00:00
|
|
|
int menu_width;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** # lines */
|
2014-03-22 20:04:19 +00:00
|
|
|
unsigned int menu_lines;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** # Columns */
|
2014-05-19 07:50:09 +00:00
|
|
|
unsigned int menu_columns;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Font string (pango format) */
|
2014-03-22 20:04:19 +00:00
|
|
|
char * menu_font;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Foreground color */
|
2014-03-22 20:04:19 +00:00
|
|
|
char * menu_fg;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Background color */
|
2014-03-22 20:04:19 +00:00
|
|
|
char * menu_bg;
|
2015-01-12 18:14:46 +00:00
|
|
|
/** Background color alt */
|
|
|
|
char * menu_bg_alt;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Highlight foreground color */
|
2014-03-22 20:04:19 +00:00
|
|
|
char * menu_hlfg;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Highlight background color */
|
2014-03-22 20:04:19 +00:00
|
|
|
char * menu_hlbg;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Border color */
|
2014-03-22 20:04:19 +00:00
|
|
|
char * menu_bc;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Terminal to use */
|
2014-03-22 20:04:19 +00:00
|
|
|
char * terminal_emulator;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** SSH client to use */
|
2014-09-03 11:07:26 +00:00
|
|
|
char * ssh_client;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Command to execute when ssh session is selected */
|
2014-09-03 11:07:26 +00:00
|
|
|
char * ssh_command;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Command for executing an application */
|
2014-09-03 11:07:26 +00:00
|
|
|
char * run_command;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Command for executing an application in a terminal */
|
2014-09-03 11:07:26 +00:00
|
|
|
char * run_shell_command;
|
2015-01-05 20:53:50 +00:00
|
|
|
/** Command for listing executables */
|
|
|
|
char * run_list_command;
|
2014-05-20 09:22:03 +00:00
|
|
|
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Windows location/gravity */
|
2014-03-22 20:04:19 +00:00
|
|
|
WindowLocation location;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Padding between elements */
|
2014-03-22 20:04:19 +00:00
|
|
|
unsigned int padding;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Y offset */
|
2014-05-15 14:54:35 +00:00
|
|
|
int y_offset;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** X offset */
|
2014-05-15 19:55:23 +00:00
|
|
|
int x_offset;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Always should config.menu_lines lines, even if less lines are available */
|
2014-05-17 20:17:07 +00:00
|
|
|
unsigned int fixed_num_lines;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Do not use history */
|
2014-06-05 19:55:47 +00:00
|
|
|
unsigned int disable_history;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Use levenshtein sorting when matching */
|
2014-07-16 06:42:42 +00:00
|
|
|
unsigned int levenshtein_sort;
|
2015-01-12 13:13:46 +00:00
|
|
|
/** Search case sensitivity */
|
|
|
|
unsigned int case_sensitive;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Separator to use for dmenu mode */
|
2014-10-19 17:42:02 +00:00
|
|
|
char separator;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Height of an element in #chars */
|
2014-10-30 16:53:22 +00:00
|
|
|
int element_height;
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Sidebar mode, show the switchers */
|
2015-02-01 09:43:28 +00:00
|
|
|
unsigned int sidebar_mode;
|
2015-01-18 17:17:09 +00:00
|
|
|
/** Lazy filter limit. */
|
|
|
|
unsigned int lazy_filter_limit;
|
2015-02-24 16:34:25 +00:00
|
|
|
/** Auto select. */
|
|
|
|
unsigned int auto_select;
|
2014-01-23 10:39:12 +00:00
|
|
|
} Settings;
|
|
|
|
|
2014-11-25 07:27:08 +00:00
|
|
|
/** Global Settings structure. */
|
2014-01-23 10:39:12 +00:00
|
|
|
extern Settings config;
|
2014-02-03 21:49:07 +00:00
|
|
|
|
2014-11-25 07:27:08 +00:00
|
|
|
/**
|
|
|
|
* @param msg The error message to show.
|
|
|
|
*
|
|
|
|
* The error message to show.
|
|
|
|
*/
|
2015-02-03 07:21:59 +00:00
|
|
|
void error_dialog ( const char *msg );
|
2014-11-25 07:27:08 +00:00
|
|
|
|
2015-03-27 19:28:53 +00:00
|
|
|
/**
|
|
|
|
* Structure defining a switcher.
|
|
|
|
* It consists of a name, callback and if enabled
|
|
|
|
* a textbox for the sidebar-mode.
|
|
|
|
*/
|
|
|
|
struct _Switcher
|
|
|
|
{
|
|
|
|
// Name (max 31 char long)
|
|
|
|
char name[32];
|
|
|
|
// Textbox used in the sidebar-mode.
|
|
|
|
textbox *tb;
|
|
|
|
// Keybindings (keysym and modmask)
|
|
|
|
char * keycfg;
|
|
|
|
char * keystr;
|
|
|
|
KeySym keysym;
|
|
|
|
unsigned int modmask;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A switcher normally consists of the following parts:
|
|
|
|
*/
|
|
|
|
void ( *init )( struct _Switcher *sw );
|
|
|
|
char ** ( *get_data )( unsigned int *length, struct _Switcher *pd );
|
|
|
|
int ( *match )( char **tokens, const char *input, int case_sensitive, int index, struct _Switcher *data );
|
|
|
|
SwitcherMode ( *result )( int menu_retv, char **input, unsigned int selected_line, struct _Switcher *pd );
|
|
|
|
void ( *destroy )( struct _Switcher *pd );
|
|
|
|
// Token match.
|
|
|
|
menu_match_cb token_match;
|
|
|
|
|
|
|
|
// Pointer to private data.
|
|
|
|
void *private_data;
|
|
|
|
|
|
|
|
// Extra fields for script
|
|
|
|
void *ed;
|
|
|
|
// Free SWitcher
|
|
|
|
switcher_free free;
|
|
|
|
};
|
|
|
|
|
2014-01-20 22:36:20 +00:00
|
|
|
#endif
|