Remove view_title

- Do not set window title, as it cannot be read
  - Print PID in event instead of title to prevent information leaks
This commit is contained in:
project-repo 2022-12-29 16:09:33 +01:00
commit c83aed6728
7 changed files with 27 additions and 55 deletions

View file

@ -838,9 +838,7 @@ print_view(struct cg_view *view) {
uint32_t nmemb = 4;
outp_str.str_arr = calloc(nmemb, sizeof(char *));
print_str(&outp_str, "\"id\": %d,\n", view->id);
char *title_str = view->impl->get_title(view);
print_str(&outp_str, "\"title\": \"%s\",\n",
title_str == NULL ? "" : title_str);
print_str(&outp_str, "\"pid\": \"%d\",\n", view->impl->get_pid(view));
print_str(&outp_str, "\"coords\": {\"x\":%d,\"y\":%d},\n", view->ox,
view->oy);
#if CG_HAS_XWAYLAND
@ -1314,18 +1312,18 @@ keybinding_move_view_to_output(struct cg_server *server, int output_num) {
workspace_tile_update_view(ws->focused_tile,view);
seat_set_focus(server->seat, view);
}
char *view_title = "";
pid_t view_pid = -1;
int view_id = -1;
if(view != NULL) {
view_title = view->impl->get_title(view);
view_pid = view->impl->get_pid(view);
view_id = view->id;
}
ipc_send_event(
server,
"{\"event_name\":\"move_view_to_output\",\"view_id\":\"%d\",\"old_"
"output\":\"%s\",\"new_output\":\"%s\",\"view_title\":\"%s\"}",
"output\":\"%s\",\"new_output\":\"%s\",\"view_pid\":\"%d\"}",
view_id, old_outp->wlr_output->name,
server->curr_output->wlr_output->name, view_title);
server->curr_output->wlr_output->name, view_pid);
}
void
@ -1358,10 +1356,10 @@ keybinding_move_view_to_workspace(struct cg_server *server, uint32_t ws) {
ipc_send_event(server,
"{\"event_name\":\"move_view_to_ws\",\"view_id\":\"%d\","
"\"old_workspace\":\"%d\",\"new_workspace\":\"%d\","
"\"output\":\"%s\",\"view_title\":\"%s\"}",
"\"output\":\"%s\",\"view_pid\":\"%d\"}",
view == NULL ? -1 : (int)view->id, old_ws, ws,
server->curr_output->wlr_output->name,
view == NULL ? "" : view->impl->get_title(view));
view == NULL ? 0 : view->impl->get_pid(view));
}
void

View file

@ -576,16 +576,3 @@ handle_new_output(struct wl_listener *listener, void *data) {
#if CG_HAS_FANALYZE
#pragma GCC diagnostic pop
#endif
void
output_set_window_title(struct cg_output *output, const char *title) {
struct wlr_output *wlr_output = output->wlr_output;
if(wlr_output_is_wl(wlr_output)) {
wlr_wl_output_set_title(wlr_output, title);
#if WLR_HAS_X11_BACKEND
} else if(wlr_output_is_x11(wlr_output)) {
wlr_x11_output_set_title(wlr_output, title);
#endif
}
}

4
seat.c
View file

@ -1040,10 +1040,6 @@ seat_set_focus(struct cg_seat *seat, struct cg_view *view) {
}
view_activate(view, true);
char *title = view_get_title(view);
output_set_window_title(server->curr_output, title);
free(title);
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(wlr_seat);
wlr_seat_keyboard_end_grab(wlr_seat);

19
view.c
View file

@ -52,15 +52,6 @@ view_get_prev_view(struct cg_view *view) {
return prev;
}
char *
view_get_title(const struct cg_view *view) {
const char *title = view->impl->get_title(view);
if(!title) {
return NULL;
}
return strndup(title, strlen(title));
}
bool
view_is_primary(const struct cg_view *view) {
return view->impl->is_primary(view);
@ -113,7 +104,7 @@ view_unmap(struct cg_view *view) {
uint32_t tile_id = 0;
uint32_t ws = view->workspace->num;
char *output_name = view->workspace->output->wlr_output->name;
char *title = view->impl->get_title(view);
pid_t pid = view->impl->get_pid(view);
/* If the view is not mapped, do nothing */
if(view->wlr_surface == NULL) {
return;
@ -162,8 +153,8 @@ view_unmap(struct cg_view *view) {
ipc_send_event(
view->workspace->server,
"{\"event_name\":\"view_unmap\",\"view_id\":\"%d\",\"tile_id\":\"%d\","
"\"workspace\":\"%d\",\"output\":\"%s\",\"view_title\":\"%s\"}",
id, tile_id, ws + 1, output_name, title);
"\"workspace\":\"%d\",\"output\":\"%s\",\"view_pid\":\"%d\"}",
id, tile_id, ws + 1, output_name, pid);
}
void
@ -205,9 +196,9 @@ view_map(struct cg_view *view, struct wlr_surface *surface,
ipc_send_event(
output->server,
"{\"event_name\":\"view_map\",\"view_id\":\"%d\",\"tile_id\":\"%d\","
"\"workspace\":\"%d\",\"output\":\"%s\",\"view_title\":\"%s\"}",
"\"workspace\":\"%d\",\"output\":\"%s\",\"view_pid\":\"%d\"}",
view->id, tile_id, view->workspace->num + 1,
view->workspace->output->wlr_output->name, view->impl->get_title(view));
view->workspace->output->wlr_output->name, view->impl->get_pid(view));
}
void

4
view.h
View file

@ -35,7 +35,7 @@ struct cg_view {
};
struct cg_view_impl {
char *(*get_title)(const struct cg_view *view);
pid_t (*get_pid)(const struct cg_view *view);
bool (*is_primary)(const struct cg_view *view);
void (*activate)(struct cg_view *view, bool activate);
void (*close)(struct cg_view *view);
@ -43,8 +43,6 @@ struct cg_view_impl {
void (*destroy)(struct cg_view *view);
};
char *
view_get_title(const struct cg_view *view);
struct cg_tile *
view_get_tile(const struct cg_view *view);
bool

View file

@ -106,11 +106,13 @@ xdg_shell_view_from_const_view(const struct cg_view *view) {
return (const struct cg_xdg_shell_view *)view;
}
static char *
get_title(const struct cg_view *view) {
const struct cg_xdg_shell_view *xdg_shell_view =
xdg_shell_view_from_const_view(view);
return xdg_shell_view->xdg_surface->toplevel->title;
static pid_t
get_pid(const struct cg_view *view) {
pid_t pid;
struct wl_client *client =
wl_resource_get_client(view->wlr_surface->resource);
wl_client_get_credentials(client, &pid, NULL, NULL);
return pid;
}
static bool
@ -198,7 +200,7 @@ handle_xdg_shell_surface_destroy(struct wl_listener *listener, void *_data) {
view_destroy(view);
}
static const struct cg_view_impl xdg_shell_view_impl = {.get_title = get_title,
static const struct cg_view_impl xdg_shell_view_impl = {.get_pid = get_pid,
.is_primary =
is_primary,
.activate = activate,

View file

@ -44,11 +44,11 @@ xwayland_view_should_manage(const struct cg_view *view) {
return !xwayland_surface->override_redirect;
}
static char *
get_title(const struct cg_view *view) {
const struct cg_xwayland_view *xwayland_view =
xwayland_view_from_const_view(view);
return xwayland_view->xwayland_surface->title;
static pid_t
get_pid(const struct cg_view *view) {
struct wlr_xwayland_surface *surf =
wlr_xwayland_surface_from_wlr_surface(view->wlr_surface);
return surf->pid;
}
static bool
@ -160,7 +160,7 @@ handle_xwayland_surface_destroy(struct wl_listener *listener, void *_data) {
}
static const struct cg_view_impl xwayland_view_impl = {
.get_title = get_title,
.get_pid = get_pid,
.is_primary = is_primary,
.activate = activate,
.close = close,