mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
Implement pango markup for -window-format (#1288)
* Implement pango markup for -window-format * Make sure role != null Since g_markup_escape_text doesn't like null it seems * Update formatting To bring it more in line with surrounding code * Address review comments * Fix memory leaks * Fix formatting
This commit is contained in:
parent
2e9835892b
commit
24dde58019
1 changed files with 38 additions and 22 deletions
|
@ -109,6 +109,7 @@ typedef struct
|
||||||
long hint_flags;
|
long hint_flags;
|
||||||
uint32_t wmdesktop;
|
uint32_t wmdesktop;
|
||||||
char *wmdesktopstr;
|
char *wmdesktopstr;
|
||||||
|
int wmdesktopstr_len;
|
||||||
cairo_surface_t *icon;
|
cairo_surface_t *icon;
|
||||||
gboolean icon_checked;
|
gboolean icon_checked;
|
||||||
uint32_t icon_fetch_uid;
|
uint32_t icon_fetch_uid;
|
||||||
|
@ -332,20 +333,24 @@ static client* window_client ( ModeModePrivateData *pd, xcb_window_t win )
|
||||||
xcb_ewmh_get_atoms_reply_wipe ( &states );
|
xcb_ewmh_get_atoms_reply_wipe ( &states );
|
||||||
}
|
}
|
||||||
|
|
||||||
c->title = window_get_text_prop ( c->window, xcb->ewmh._NET_WM_NAME );
|
char *tmp_title = window_get_text_prop ( c->window, xcb->ewmh._NET_WM_NAME );
|
||||||
if ( c->title == NULL ) {
|
if ( tmp_title == NULL ) {
|
||||||
c->title = window_get_text_prop ( c->window, XCB_ATOM_WM_NAME );
|
tmp_title = window_get_text_prop ( c->window, XCB_ATOM_WM_NAME );
|
||||||
}
|
}
|
||||||
|
c->title = g_markup_escape_text ( tmp_title, -1 );
|
||||||
pd->title_len = MAX ( c->title ? g_utf8_strlen ( c->title, -1 ) : 0, pd->title_len );
|
pd->title_len = MAX ( c->title ? g_utf8_strlen ( c->title, -1 ) : 0, pd->title_len );
|
||||||
|
g_free ( tmp_title );
|
||||||
|
|
||||||
c->role = window_get_text_prop ( c->window, netatoms[WM_WINDOW_ROLE] );
|
char *tmp_role = window_get_text_prop ( c->window, netatoms[WM_WINDOW_ROLE] );
|
||||||
|
c->role = g_markup_escape_text ( tmp_role ? tmp_role : "", -1 );
|
||||||
pd->role_len = MAX ( c->role ? g_utf8_strlen ( c->role, -1 ) : 0, pd->role_len );
|
pd->role_len = MAX ( c->role ? g_utf8_strlen ( c->role, -1 ) : 0, pd->role_len );
|
||||||
|
g_free ( tmp_role );
|
||||||
|
|
||||||
cky = xcb_icccm_get_wm_class ( xcb->connection, c->window );
|
cky = xcb_icccm_get_wm_class ( xcb->connection, c->window );
|
||||||
xcb_icccm_get_wm_class_reply_t wcr;
|
xcb_icccm_get_wm_class_reply_t wcr;
|
||||||
if ( xcb_icccm_get_wm_class_reply ( xcb->connection, cky, &wcr, NULL ) ) {
|
if ( xcb_icccm_get_wm_class_reply ( xcb->connection, cky, &wcr, NULL ) ) {
|
||||||
c->class = rofi_latin_to_utf8_strdup ( wcr.class_name, -1 );
|
c->class = g_markup_escape_text( wcr.class_name, -1 );
|
||||||
c->name = rofi_latin_to_utf8_strdup ( wcr.instance_name, -1 );
|
c->name = g_markup_escape_text( wcr.instance_name, -1 );
|
||||||
pd->name_len = MAX ( c->name ? g_utf8_strlen ( c->name, -1 ) : 0, pd->name_len );
|
pd->name_len = MAX ( c->name ? g_utf8_strlen ( c->name, -1 ) : 0, pd->name_len );
|
||||||
xcb_icccm_get_wm_class_reply_wipe ( &wcr );
|
xcb_icccm_get_wm_class_reply_wipe ( &wcr );
|
||||||
}
|
}
|
||||||
|
@ -560,24 +565,30 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
|
||||||
char *output = NULL;
|
char *output = NULL;
|
||||||
if ( pango_parse_markup ( _window_name_list_entry ( names.strings, names.strings_len,
|
if ( pango_parse_markup ( _window_name_list_entry ( names.strings, names.strings_len,
|
||||||
c->wmdesktop ), -1, 0, NULL, &output, NULL, NULL ) ) {
|
c->wmdesktop ), -1, 0, NULL, &output, NULL, NULL ) ) {
|
||||||
c->wmdesktopstr = output;
|
c->wmdesktopstr = g_strdup ( _window_name_list_entry ( names.strings, names.strings_len, c->wmdesktop ) );
|
||||||
|
c->wmdesktopstr_len = g_utf8_strlen ( output, -1 );
|
||||||
|
pd->wmdn_len = MAX ( pd->wmdn_len, c->wmdesktopstr_len );
|
||||||
|
g_free ( output );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
c->wmdesktopstr = g_strdup ( "Invalid name" );
|
c->wmdesktopstr = g_strdup ( "Invalid name" );
|
||||||
|
pd->wmdn_len = MAX ( pd->wmdn_len, g_utf8_strlen ( c->wmdesktopstr, -1 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
c->wmdesktopstr = g_strdup ( _window_name_list_entry ( names.strings, names.strings_len, c->wmdesktop ) );
|
c->wmdesktopstr = g_markup_escape_text ( _window_name_list_entry ( names.strings, names.strings_len, c->wmdesktop ), -1 );
|
||||||
|
pd->wmdn_len = MAX ( pd->wmdn_len, g_utf8_strlen ( c->wmdesktopstr, -1 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
c->wmdesktopstr = g_strdup_printf ( "%u", (uint32_t) c->wmdesktop );
|
c->wmdesktopstr = g_strdup_printf ( "%u", (uint32_t) c->wmdesktop );
|
||||||
|
pd->wmdn_len = MAX ( pd->wmdn_len, g_utf8_strlen ( c->wmdesktopstr, -1 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
c->wmdesktopstr = g_strdup ( "" );
|
c->wmdesktopstr = g_strdup ( "" );
|
||||||
}
|
|
||||||
pd->wmdn_len = MAX ( pd->wmdn_len, g_utf8_strlen ( c->wmdesktopstr, -1 ) );
|
pd->wmdn_len = MAX ( pd->wmdn_len, g_utf8_strlen ( c->wmdesktopstr, -1 ) );
|
||||||
|
}
|
||||||
if ( cd && c->wmdesktop != current_desktop ) {
|
if ( cd && c->wmdesktop != current_desktop ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -739,12 +750,11 @@ struct arg
|
||||||
client *c;
|
client *c;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void helper_eval_add_str ( GString *str, const char *input, int l, int max_len )
|
static void helper_eval_add_str ( GString *str, const char *input, int l, int max_len, int nc )
|
||||||
{
|
{
|
||||||
// g_utf8 does not work with NULL string.
|
// g_utf8 does not work with NULL string.
|
||||||
const char *input_nn = input ? input : "";
|
const char *input_nn = input ? input : "";
|
||||||
// Both l and max_len are in characters, not bytes.
|
// Both l and max_len are in characters, not bytes.
|
||||||
int nc = g_utf8_strlen ( input_nn, -1 );
|
|
||||||
int spaces = 0;
|
int spaces = 0;
|
||||||
if ( l == 0 ) {
|
if ( l == 0 ) {
|
||||||
spaces = MAX ( 0, max_len - nc );
|
spaces = MAX ( 0, max_len - nc );
|
||||||
|
@ -753,11 +763,15 @@ static void helper_eval_add_str ( GString *str, const char *input, int l, int ma
|
||||||
else {
|
else {
|
||||||
if ( nc > l ) {
|
if ( nc > l ) {
|
||||||
int bl = g_utf8_offset_to_pointer ( input_nn, l ) - input_nn;
|
int bl = g_utf8_offset_to_pointer ( input_nn, l ) - input_nn;
|
||||||
g_string_append_len ( str, input_nn, bl );
|
char *tmp = g_markup_escape_text ( input_nn, bl );
|
||||||
|
g_string_append ( str, tmp );
|
||||||
|
g_free ( tmp );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
spaces = l - nc;
|
spaces = l - nc;
|
||||||
g_string_append ( str, input_nn );
|
char *tmp = g_markup_escape_text ( input_nn, -1 );
|
||||||
|
g_string_append ( str, tmp );
|
||||||
|
g_free ( tmp );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while ( spaces-- ) {
|
while ( spaces-- ) {
|
||||||
|
@ -782,20 +796,21 @@ static gboolean helper_eval_cb ( const GMatchInfo *info, GString *str, gpointer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( match[1] == 'w' ) {
|
if ( match[1] == 'w' ) {
|
||||||
helper_eval_add_str ( str, d->c->wmdesktopstr, l, d->pd->wmdn_len );
|
helper_eval_add_str ( str, d->c->wmdesktopstr, l, d->pd->wmdn_len, d->c->wmdesktopstr_len );
|
||||||
}
|
}
|
||||||
else if ( match[1] == 'c' ) {
|
else if ( match[1] == 'c' ) {
|
||||||
helper_eval_add_str ( str, d->c->class, l, d->pd->clf_len );
|
helper_eval_add_str ( str, d->c->class, l, d->pd->clf_len, g_utf8_strlen ( d->c->class, -1 ) );
|
||||||
}
|
}
|
||||||
else if ( match[1] == 't' ) {
|
else if ( match[1] == 't' ) {
|
||||||
helper_eval_add_str ( str, d->c->title, l, d->pd->title_len );
|
helper_eval_add_str ( str, d->c->title, l, d->pd->title_len, g_utf8_strlen ( d->c->title, -1 ) );
|
||||||
}
|
}
|
||||||
else if ( match[1] == 'n' ) {
|
else if ( match[1] == 'n' ) {
|
||||||
helper_eval_add_str ( str, d->c->name, l, d->pd->name_len );
|
helper_eval_add_str ( str, d->c->name, l, d->pd->name_len, g_utf8_strlen ( d->c->name, -1 ) );
|
||||||
}
|
}
|
||||||
else if ( match[1] == 'r' ) {
|
else if ( match[1] == 'r' ) {
|
||||||
helper_eval_add_str ( str, d->c->role, l, d->pd->role_len );
|
helper_eval_add_str ( str, d->c->role, l, d->pd->role_len, g_utf8_strlen ( d->c->role, -1 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free ( match );
|
g_free ( match );
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -821,6 +836,7 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, in
|
||||||
if ( c->active ) {
|
if ( c->active ) {
|
||||||
*state |= ACTIVE;
|
*state |= ACTIVE;
|
||||||
}
|
}
|
||||||
|
*state |= MARKUP;
|
||||||
return get_entry ? _generate_display_string ( rmpd, c ) : NULL;
|
return get_entry ? _generate_display_string ( rmpd, c ) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue