Set window title based on mode name.

For dmenu allow customize with `-window-title`.

Fixes: #969
This commit is contained in:
Dave Davenport 2019-08-10 12:02:49 +02:00
parent 204008d389
commit 85279323e6
5 changed files with 836 additions and 1222 deletions

1971
doc/rofi.1

File diff suppressed because it is too large Load Diff

View File

@ -662,6 +662,10 @@ Reads the first 25 entries blocking, then switches to async mode. This makes it
*default*: 25
`-window-title` *title*
Set name used for the window title. Will be shown as Rofi - *title*
### Message dialog
`-e` *message*

View File

@ -302,5 +302,9 @@ void rofi_view_get_current_monitor ( int *width, int *height );
* Takes a screenshot.
*/
void rofi_capture_screenshot ( void );
/**
* Set the window title.
*/
void rofi_view_set_window_title ( const char * title );
/**@}*/
#endif

View File

@ -53,6 +53,12 @@
#include "dialogs/dmenuscriptshared.h"
static int dmenu_mode_init ( Mode *sw );
static int dmenu_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index );
static cairo_surface_t *dmenu_get_icon ( const Mode *sw, unsigned int selected_line, int height );
static char *dmenu_get_message ( const Mode *sw );
static inline unsigned int bitget ( uint32_t *array, unsigned int index )
{
uint32_t bit = index % 32;
@ -315,6 +321,27 @@ static void dmenu_mode_free ( Mode *sw )
}
}
#include "mode-private.h"
/** dmenu Mode object. */
Mode dmenu_mode =
{
.name = "dmenu",
.cfg_name_key = "display-combi",
._init = dmenu_mode_init,
._get_num_entries = dmenu_mode_get_num_entries,
._result = NULL,
._destroy = dmenu_mode_free,
._token_match = dmenu_token_match,
._get_display_value = get_display_data,
._get_icon = dmenu_get_icon,
._get_completion = NULL,
._preprocess_input = NULL,
._get_message = dmenu_get_message,
.private_data = NULL,
.free = NULL,
.display_name = "dmenu"
};
static int dmenu_mode_init ( Mode *sw )
{
if ( mode_get_private_data ( sw ) != NULL ) {
@ -353,6 +380,12 @@ static int dmenu_mode_init ( Mode *sw )
// DMENU COMPATIBILITY
find_arg_uint ( "-l", &( config.menu_lines ) );
str = NULL;
find_arg_str ( "-window-title", &str );
if ( str ) {
dmenu_mode.display_name = str;
}
/**
* Dmenu compatibility.
* `-b` put on bottom.
@ -436,26 +469,6 @@ static cairo_surface_t *dmenu_get_icon ( const Mode *sw, unsigned int selected_l
return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
}
#include "mode-private.h"
/** dmenu Mode object. */
Mode dmenu_mode =
{
.name = "dmenu",
.cfg_name_key = "display-combi",
._init = dmenu_mode_init,
._get_num_entries = dmenu_mode_get_num_entries,
._result = NULL,
._destroy = dmenu_mode_free,
._token_match = dmenu_token_match,
._get_display_value = get_display_data,
._get_icon = dmenu_get_icon,
._get_completion = NULL,
._preprocess_input = NULL,
._get_message = dmenu_get_message,
.private_data = NULL,
.free = NULL,
.display_name = "dmenu"
};
static void dmenu_finish ( RofiViewState *state, int retv )
{
@ -709,6 +722,7 @@ void print_dmenu_options ( void )
print_help_msg ( "-u", "[list]", "List of row indexes to mark urgent", NULL, is_term );
print_help_msg ( "-a", "[list]", "List of row indexes to mark active", NULL, is_term );
print_help_msg ( "-l", "[integer] ", "Number of rows to display", NULL, is_term );
print_help_msg ( "-window-title", "[string] ", "Set the dmenu window title", NULL, is_term );
print_help_msg ( "-i", "", "Set filter to be case insensitive", NULL, is_term );
print_help_msg ( "-only-match", "", "Force selection or custom entry", NULL, is_term );
print_help_msg ( "-no-custom", "", "Don't accept custom entry", NULL, is_term );

View File

@ -790,9 +790,7 @@ void __create_window ( MenuFlags menu_flags )
TICK_N ( "setup window fullscreen" );
// Set the WM_NAME
xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box_window, xcb->ewmh._NET_WM_NAME, xcb->ewmh.UTF8_STRING, 8, 4, "rofi" );
xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box_window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, 4, "rofi" );
rofi_view_set_window_title ( "rofi" );
const char wm_class_name[] = "rofi\0Rofi";
xcb_icccm_set_wm_class ( xcb->connection, box_window, sizeof ( wm_class_name ), wm_class_name );
@ -1715,6 +1713,13 @@ RofiViewState *rofi_view_create ( Mode *sw,
// Request the lines to show.
state->num_lines = mode_get_num_entries ( sw );
if ( state->sw ) {
char * title = g_strdup_printf ( "rofi - %s", mode_get_display_name (state->sw ) );
rofi_view_set_window_title ( title );
g_free ( title );
} else {
rofi_view_set_window_title ( "rofi" );
}
TICK_N ( "Startup notification" );
// Get active monitor size.
@ -1921,6 +1926,13 @@ void rofi_view_switch_mode ( RofiViewState *state, Mode *mode )
if ( state->prompt ) {
rofi_view_update_prompt ( state );
}
if ( state->sw ) {
char * title = g_strdup_printf ( "rofi - %s", mode_get_display_name (state->sw ) );
rofi_view_set_window_title ( title );
g_free ( title );
} else {
rofi_view_set_window_title ( "rofi" );
}
if ( state->sidebar_bar ) {
for ( unsigned int j = 0; j < state->num_modi; j++ ) {
const Mode * mode = rofi_get_mode ( j );
@ -1938,3 +1950,10 @@ xcb_window_t rofi_view_get_window ( void )
{
return CacheState.main_window;
}
void rofi_view_set_window_title ( const char * title )
{
ssize_t len = strlen(title);
xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, CacheState.main_window, xcb->ewmh._NET_WM_NAME, xcb->ewmh.UTF8_STRING, 8, len, title );
xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, CacheState.main_window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, len, title );
}