mirror of
https://github.com/labwc/labwc.git
synced 2025-11-30 06:59:52 -05:00
view: store title/app_id in view
This simplifies our codes and eliminates duplicated
`view.events.new_{title,app_id}` events. This should not change any
behaviors.
This commit is contained in:
parent
27cc738985
commit
babd7af8f8
13 changed files with 87 additions and 155 deletions
45
src/view.c
45
src/view.c
|
|
@ -133,11 +133,11 @@ view_contains_window_type(struct view *view, enum lab_window_type window_type)
|
|||
bool
|
||||
view_matches_query(struct view *view, struct view_query *query)
|
||||
{
|
||||
if (!query_str_match(query->identifier, view_get_string_prop(view, "app_id"))) {
|
||||
if (!query_str_match(query->identifier, view->app_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!query_str_match(query->title, view_get_string_prop(view, "title"))) {
|
||||
if (!query_str_match(query->title, view->title)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -2385,31 +2385,36 @@ view_has_strut_partial(struct view *view)
|
|||
view->impl->has_strut_partial(view);
|
||||
}
|
||||
|
||||
/* Note: It is safe to assume that this function never returns NULL */
|
||||
const char *
|
||||
view_get_string_prop(struct view *view, const char *prop)
|
||||
{
|
||||
assert(view);
|
||||
assert(prop);
|
||||
if (view->impl->get_string_prop) {
|
||||
const char *ret = view->impl->get_string_prop(view, prop);
|
||||
return ret ? ret : "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void
|
||||
view_update_title(struct view *view)
|
||||
view_set_title(struct view *view, const char *title)
|
||||
{
|
||||
assert(view);
|
||||
if (!title) {
|
||||
title = "";
|
||||
}
|
||||
|
||||
if (!strcmp(view->title, title)) {
|
||||
return;
|
||||
}
|
||||
xstrdup_replace(view->title, title);
|
||||
|
||||
ssd_update_title(view->ssd);
|
||||
wl_signal_emit_mutable(&view->events.new_title, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
view_update_app_id(struct view *view)
|
||||
view_set_app_id(struct view *view, const char *app_id)
|
||||
{
|
||||
assert(view);
|
||||
if (!app_id) {
|
||||
app_id = "";
|
||||
}
|
||||
|
||||
if (!strcmp(view->app_id, app_id)) {
|
||||
return;
|
||||
}
|
||||
xstrdup_replace(view->app_id, app_id);
|
||||
|
||||
wl_signal_emit_mutable(&view->events.new_app_id, NULL);
|
||||
}
|
||||
|
||||
|
|
@ -2562,6 +2567,9 @@ view_init(struct view *view)
|
|||
wl_signal_init(&view->events.activated);
|
||||
wl_signal_init(&view->events.set_icon);
|
||||
wl_signal_init(&view->events.destroy);
|
||||
|
||||
view->title = xstrdup("");
|
||||
view->app_id = xstrdup("");
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -2585,6 +2593,9 @@ view_destroy(struct view *view)
|
|||
wl_list_remove(&view->set_title.link);
|
||||
wl_list_remove(&view->destroy.link);
|
||||
|
||||
zfree(view->title);
|
||||
zfree(view->app_id);
|
||||
|
||||
if (view->foreign_toplevel) {
|
||||
foreign_toplevel_destroy(view->foreign_toplevel);
|
||||
view->foreign_toplevel = NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue