mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
Allow modes to set message box, instead of view creation argument.
This commit is contained in:
parent
8aac855fe0
commit
45c70cbecf
7 changed files with 59 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
|||
#ifndef ROFI_MODE_PRIVATE_H
|
||||
#define ROFI_MODE_PRIVATE_H
|
||||
|
||||
#define ABI_VERSION 0x00000001
|
||||
#define ABI_VERSION 0x00000002
|
||||
|
||||
/**
|
||||
* @param data Pointer to #Mode object.
|
||||
|
@ -93,6 +93,15 @@ typedef ModeMode ( *_mode_result )( Mode *sw, int menu_retv, char **input, unsig
|
|||
*/
|
||||
typedef char* ( *_mode_preprocess_input )( Mode *sw, const char *input );
|
||||
|
||||
/**
|
||||
* @param sw The #Mode pointer
|
||||
*
|
||||
* Message to show in the message bar.
|
||||
*
|
||||
* @returns the (valid pango markup) message to display.
|
||||
*/
|
||||
typedef char * (*_mode_get_message )( const Mode *sw );
|
||||
|
||||
/**
|
||||
* Structure defining a switcher.
|
||||
* It consists of a name, callback and if enabled
|
||||
|
@ -127,6 +136,8 @@ struct rofi_mode
|
|||
|
||||
_mode_preprocess_input _preprocess_input;
|
||||
|
||||
_mode_get_message _get_message;
|
||||
|
||||
/** Pointer to private data. */
|
||||
void *private_data;
|
||||
|
||||
|
|
|
@ -185,5 +185,14 @@ void mode_set_config ( Mode *mode );
|
|||
* @returns a newly allocated string
|
||||
*/
|
||||
char * mode_preprocess_input ( Mode *mode, const char *input );
|
||||
|
||||
/**
|
||||
* @param mode The mode to query
|
||||
*
|
||||
* Query the mode for a user display.
|
||||
*
|
||||
* @return a new allocated (valid pango markup) message to display (user should free).
|
||||
*/
|
||||
char *mode_get_message ( const Mode *mode );
|
||||
/*@}*/
|
||||
#endif
|
||||
|
|
|
@ -33,7 +33,6 @@ typedef enum
|
|||
/**
|
||||
* @param sw the Mode to show.
|
||||
* @param input A pointer to a string where the inputted data is placed.
|
||||
* @param message Extra message to display.
|
||||
* @param flags Flags indicating state of the menu.
|
||||
* @param finalize the finailze callback
|
||||
*
|
||||
|
@ -41,7 +40,7 @@ typedef enum
|
|||
*
|
||||
* @returns The command issued (see MenuReturn)
|
||||
*/
|
||||
RofiViewState *rofi_view_create ( Mode *sw, const char *input, const char *message, MenuFlags flags, void ( *finalize )( RofiViewState * ) );
|
||||
RofiViewState *rofi_view_create ( Mode *sw, const char *input, MenuFlags flags, void ( *finalize )( RofiViewState * ) );
|
||||
|
||||
/**
|
||||
* @param state The Menu Handle
|
||||
|
|
|
@ -470,6 +470,14 @@ static int dmenu_token_match ( const Mode *sw, GRegex **tokens, unsigned int ind
|
|||
DmenuModePrivateData *rmpd = (DmenuModePrivateData *) mode_get_private_data ( sw );
|
||||
return helper_token_match ( tokens, rmpd->cmd_list[index] );
|
||||
}
|
||||
static char *dmenu_get_message ( const Mode *sw )
|
||||
{
|
||||
DmenuModePrivateData *pd = (DmenuModePrivateData *) mode_get_private_data ( sw );
|
||||
if ( pd->message ){
|
||||
return g_strdup ( pd->message );
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#include "mode-private.h"
|
||||
/** dmenu Mode object. */
|
||||
|
@ -485,6 +493,7 @@ Mode dmenu_mode =
|
|||
._get_display_value = get_display_data,
|
||||
._get_completion = NULL,
|
||||
._preprocess_input = NULL,
|
||||
._get_message = dmenu_get_message,
|
||||
.private_data = NULL,
|
||||
.free = NULL,
|
||||
.display_name = "dmenu:"
|
||||
|
@ -697,7 +706,7 @@ int dmenu_switcher_dialog ( void )
|
|||
return TRUE;
|
||||
}
|
||||
find_arg_str ( "-p", &( dmenu_mode.display_name ) );
|
||||
RofiViewState *state = rofi_view_create ( &dmenu_mode, input, pd->message, menu_flags, dmenu_finalize );
|
||||
RofiViewState *state = rofi_view_create ( &dmenu_mode, input, menu_flags, dmenu_finalize );
|
||||
// @TODO we should do this better.
|
||||
if ( async ) {
|
||||
rofi_view_set_overlay ( state, "Loading.. " );
|
||||
|
|
|
@ -124,4 +124,11 @@ char * mode_preprocess_input ( Mode *mode, const char *input )
|
|||
}
|
||||
return g_strdup ( input );
|
||||
}
|
||||
char *mode_get_message ( const Mode *mode )
|
||||
{
|
||||
if ( mode->_get_message ) {
|
||||
return mode->_get_message ( mode );
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
/*@}*/
|
||||
|
|
|
@ -196,7 +196,7 @@ static void run_switcher ( ModeMode mode )
|
|||
return;
|
||||
}
|
||||
curr_switcher = mode;
|
||||
RofiViewState * state = rofi_view_create ( modi[mode], config.filter, NULL, MENU_PROMPT_COLON, process_result );
|
||||
RofiViewState * state = rofi_view_create ( modi[mode], config.filter, MENU_PROMPT_COLON, process_result );
|
||||
if ( state ) {
|
||||
rofi_view_set_active ( state );
|
||||
}
|
||||
|
|
|
@ -374,6 +374,22 @@ static void rofi_view_window_update_size ( RofiViewState * state )
|
|||
widget_resize ( WIDGET ( state->main_window ), state->width, state->height );
|
||||
}
|
||||
|
||||
|
||||
static void rofi_view_reload_message_bar ( RofiViewState *state )
|
||||
{
|
||||
if ( state->mesg_box == NULL ){
|
||||
return ;
|
||||
}
|
||||
char *msg = mode_get_message ( state->sw );
|
||||
if ( msg ) {
|
||||
textbox_text ( state->mesg_tb, msg );
|
||||
widget_enable ( WIDGET (state->mesg_box ) );
|
||||
g_free ( msg );
|
||||
} else {
|
||||
widget_disable ( WIDGET (state->mesg_box ) );
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean rofi_view_reload_idle ( G_GNUC_UNUSED gpointer data )
|
||||
{
|
||||
if ( current_active_menu ) {
|
||||
|
@ -1002,6 +1018,7 @@ static void _rofi_view_reload_row ( RofiViewState *state )
|
|||
state->line_map = g_malloc0_n ( state->num_lines, sizeof ( unsigned int ) );
|
||||
state->distance = g_malloc0_n ( state->num_lines, sizeof ( int ) );
|
||||
listview_set_max_lines ( state->list_view, state->num_lines );
|
||||
rofi_view_reload_message_bar ( state );
|
||||
}
|
||||
|
||||
static void rofi_view_refilter ( RofiViewState *state )
|
||||
|
@ -1524,7 +1541,6 @@ static void rofi_view_listview_mouse_activated_cb ( listview *lv, xcb_button_pre
|
|||
|
||||
RofiViewState *rofi_view_create ( Mode *sw,
|
||||
const char *input,
|
||||
const char *message,
|
||||
MenuFlags menu_flags,
|
||||
void ( *finalize )( RofiViewState * ) )
|
||||
{
|
||||
|
@ -1593,11 +1609,9 @@ RofiViewState *rofi_view_create ( Mode *sw,
|
|||
|
||||
textbox_text ( state->case_indicator, get_matching_state () );
|
||||
state->mesg_box = container_create ( "window.mainbox.message.box" );
|
||||
state->mesg_tb = textbox_create ( "window.mainbox.message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, message );
|
||||
state->mesg_tb = textbox_create ( "window.mainbox.message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, NULL );
|
||||
container_add ( state->mesg_box, WIDGET ( state->mesg_tb ) );
|
||||
if ( message == NULL ) {
|
||||
widget_disable ( WIDGET( state->mesg_box ) );
|
||||
}
|
||||
rofi_view_reload_message_bar ( state );
|
||||
box_add ( state->main_box, WIDGET ( state->mesg_box ), FALSE, end ? 8 : 2 );
|
||||
|
||||
state->overlay = textbox_create ( "window.overlay", TB_AUTOWIDTH | TB_AUTOHEIGHT, URGENT, "blaat" );
|
||||
|
|
Loading…
Reference in a new issue