2016-01-09 15:22:09 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <string.h>
|
2016-01-07 18:47:37 +00:00
|
|
|
#include "rofi.h"
|
2016-01-07 20:27:20 +00:00
|
|
|
#include "xrmoptions.h"
|
|
|
|
#include "x11-helper.h"
|
2016-01-07 18:47:37 +00:00
|
|
|
#include "mode.h"
|
|
|
|
|
|
|
|
// This one should only be in mode implementations.
|
|
|
|
#include "mode-private.h"
|
|
|
|
/**
|
|
|
|
* @ingroup MODE
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2016-01-08 08:16:59 +00:00
|
|
|
int mode_init ( Mode *mode )
|
2016-01-07 18:47:37 +00:00
|
|
|
{
|
2016-01-08 08:16:59 +00:00
|
|
|
g_return_val_if_fail ( mode != NULL, FALSE );
|
|
|
|
g_return_val_if_fail ( mode->_init != NULL, FALSE );
|
2016-01-07 18:47:37 +00:00
|
|
|
mode->_init ( mode );
|
2016-01-08 08:16:59 +00:00
|
|
|
return TRUE;
|
2016-01-07 18:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void mode_destroy ( Mode *mode )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
|
|
|
g_assert ( mode->_destroy != NULL );
|
|
|
|
mode->_destroy ( mode );
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int mode_get_num_entries ( const Mode *mode )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
|
|
|
g_assert ( mode->_get_num_entries != NULL );
|
|
|
|
return mode->_get_num_entries ( mode );
|
|
|
|
}
|
|
|
|
|
|
|
|
char * mode_get_display_value ( const Mode *mode, unsigned int selected_line, int *state, int get_entry )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
2016-01-07 20:37:03 +00:00
|
|
|
g_assert ( state != NULL );
|
2016-01-07 20:27:20 +00:00
|
|
|
g_assert ( mode->_get_display_value != NULL );
|
2016-01-07 18:47:37 +00:00
|
|
|
|
2016-01-07 20:27:20 +00:00
|
|
|
return mode->_get_display_value ( mode, selected_line, state, get_entry );
|
|
|
|
}
|
|
|
|
|
|
|
|
char * mode_get_completion ( const Mode *mode, unsigned int selected_line )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
|
|
|
if ( mode->_get_completion != NULL ) {
|
|
|
|
return mode->_get_completion ( mode, selected_line );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int state;
|
|
|
|
g_assert ( mode->_get_display_value != NULL );
|
|
|
|
return mode->_get_display_value ( mode, selected_line, &state, TRUE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int mode_is_not_ascii ( const Mode *mode, unsigned int selected_line )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
|
|
|
g_assert ( mode->_is_not_ascii != NULL );
|
|
|
|
return mode->_is_not_ascii ( mode, selected_line );
|
|
|
|
}
|
|
|
|
ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int selected_line )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
|
|
|
g_assert ( mode->_result != NULL );
|
2016-01-08 08:16:59 +00:00
|
|
|
g_assert ( ( *input ) != NULL );
|
2016-01-07 20:27:20 +00:00
|
|
|
return mode->_result ( mode, menu_retv, input, selected_line );
|
|
|
|
}
|
|
|
|
|
|
|
|
int mode_token_match ( const Mode *mode, char **tokens, int not_ascii, int case_sensitive, unsigned int selected_line )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
|
|
|
g_assert ( mode->_token_match != NULL );
|
|
|
|
return mode->_token_match ( mode, tokens, not_ascii, case_sensitive, selected_line );
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *mode_get_name ( const Mode *mode )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
|
|
|
return mode->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mode_setup_keybinding ( Mode *mode )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
|
|
|
mode->keycfg = g_strdup_printf ( "key-%s", mode->name );
|
|
|
|
config_parser_add_option ( xrm_String, mode->keycfg, (void * *) &( mode->keystr ), "Keybinding" );
|
|
|
|
}
|
|
|
|
|
|
|
|
int mode_check_keybinding ( const Mode *mode, KeySym key, unsigned int modstate )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
|
|
|
if ( mode->keystr != NULL ) {
|
|
|
|
if ( mode->modmask == modstate && mode->keysym == key ) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mode_free ( Mode **mode )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
2016-01-08 08:16:59 +00:00
|
|
|
g_assert ( ( *mode ) != NULL );
|
2016-01-07 20:27:20 +00:00
|
|
|
if ( ( *mode )->keycfg != NULL ) {
|
|
|
|
g_free ( ( *mode )->keycfg );
|
|
|
|
( *mode )->keycfg = NULL;
|
|
|
|
}
|
|
|
|
if ( ( *mode )->free != NULL ) {
|
|
|
|
( *mode )->free ( *mode );
|
|
|
|
}
|
|
|
|
( *mode ) = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mode_grab_key ( Mode *mode, Display *display )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
2016-01-07 20:37:03 +00:00
|
|
|
g_assert ( display != NULL );
|
2016-01-07 20:27:20 +00:00
|
|
|
if ( mode->keystr != NULL ) {
|
|
|
|
x11_parse_key ( mode->keystr, &( mode->modmask ), &( mode->keysym ) );
|
|
|
|
if ( mode->keysym != NoSymbol ) {
|
|
|
|
x11_grab_key ( display, mode->modmask, mode->keysym );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
void mode_ungrab_key ( Mode *mode, Display *display )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
2016-01-07 20:37:03 +00:00
|
|
|
g_assert ( display != NULL );
|
2016-01-07 20:27:20 +00:00
|
|
|
if ( mode->keystr != NULL ) {
|
|
|
|
if ( mode->keysym != NoSymbol ) {
|
|
|
|
x11_ungrab_key ( display, mode->modmask, mode->keysym );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mode_print_keybindings ( const Mode *mode )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
|
|
|
if ( mode->keystr != NULL ) {
|
|
|
|
fprintf ( stdout, "\t* "color_bold "%s"color_reset " on %s\n", mode->name, mode->keystr );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf ( stdout, "\t* "color_bold "%s"color_reset " on <unspecified>\n", mode->name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void *mode_get_private_data ( const Mode *mode )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
|
|
|
return mode->private_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mode_set_private_data ( Mode *mode, void *pd )
|
|
|
|
{
|
|
|
|
g_assert ( mode != NULL );
|
|
|
|
if ( pd != NULL ) {
|
|
|
|
g_assert ( mode->private_data == NULL );
|
|
|
|
}
|
|
|
|
mode->private_data = pd;
|
2016-01-07 18:47:37 +00:00
|
|
|
}
|
2016-01-12 21:17:53 +00:00
|
|
|
|
|
|
|
const char *mode_get_display_name ( const Mode *mode )
|
|
|
|
{
|
|
|
|
if ( mode->display_name != NULL ) {
|
|
|
|
return mode->display_name;
|
|
|
|
}
|
|
|
|
return mode->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mode_set_config ( Mode *mode )
|
|
|
|
{
|
|
|
|
snprintf ( mode->cfg_name_key, 128, "display-%s", mode->name );
|
|
|
|
mode->display_name = g_strdup_printf ( "(%s)", mode->name );
|
|
|
|
config_parser_add_option ( xrm_String, mode->cfg_name_key, (void * *) &( mode->display_name ), "The display name of this browser" );
|
|
|
|
}
|
2016-01-07 18:47:37 +00:00
|
|
|
/*@}*/
|