mirror of
https://github.com/cage-kiosk/cage.git
synced 2025-10-29 05:40:19 -04:00
Set Cage's window title to toplevel's title
When using the Wayland or X11 backend, Cage is drawn inside a window. This commit sets this window's title to that of the currently focused toplevel window inside Cage. Fixes #29.
This commit is contained in:
parent
443d955dfd
commit
c00ac5c462
7 changed files with 53 additions and 1 deletions
22
cage.c
22
cage.c
|
|
@ -17,6 +17,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
#include <wlr/backend.h>
|
#include <wlr/backend.h>
|
||||||
|
#include <wlr/backend/wayland.h>
|
||||||
|
#include <wlr/backend/x11.h>
|
||||||
#include <wlr/render/wlr_renderer.h>
|
#include <wlr/render/wlr_renderer.h>
|
||||||
#include <wlr/types/wlr_compositor.h>
|
#include <wlr/types/wlr_compositor.h>
|
||||||
#include <wlr/types/wlr_data_device.h>
|
#include <wlr/types/wlr_data_device.h>
|
||||||
|
|
@ -36,11 +38,31 @@
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "seat.h"
|
#include "seat.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
#include "view.h"
|
||||||
#include "xdg_shell.h"
|
#include "xdg_shell.h"
|
||||||
#if CAGE_HAS_XWAYLAND
|
#if CAGE_HAS_XWAYLAND
|
||||||
#include "xwayland.h"
|
#include "xwayland.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
set_window_title(struct cg_server *server, struct cg_view *view)
|
||||||
|
{
|
||||||
|
struct wlr_output *output = server->output->wlr_output;
|
||||||
|
bool is_wl = wlr_output_is_wl(output);
|
||||||
|
bool is_x11 = wlr_output_is_x11(output);
|
||||||
|
|
||||||
|
if (!is_wl && !is_x11) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *title = view_get_title(view);
|
||||||
|
if (is_wl) {
|
||||||
|
wlr_wl_output_set_title(output, title);
|
||||||
|
} else if (is_x11) {
|
||||||
|
wlr_x11_output_set_title(output, title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
spawn_primary_client(char *argv[], pid_t *pid_out)
|
spawn_primary_client(char *argv[], pid_t *pid_out)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
3
seat.c
3
seat.c
|
|
@ -724,7 +724,8 @@ seat_set_focus(struct cg_seat *seat, struct cg_view *view)
|
||||||
wl_list_insert(&server->views, &view->link);
|
wl_list_insert(&server->views, &view->link);
|
||||||
}
|
}
|
||||||
|
|
||||||
view_activate(view, true);
|
view_activate(view, true);
|
||||||
|
set_window_title(server, view);
|
||||||
|
|
||||||
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(wlr_seat);
|
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(wlr_seat);
|
||||||
if (keyboard) {
|
if (keyboard) {
|
||||||
|
|
|
||||||
3
server.h
3
server.h
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "seat.h"
|
#include "seat.h"
|
||||||
|
#include "view.h"
|
||||||
|
|
||||||
struct cg_server {
|
struct cg_server {
|
||||||
struct wl_display *wl_display;
|
struct wl_display *wl_display;
|
||||||
|
|
@ -37,4 +38,6 @@ struct cg_server {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void set_window_title(struct cg_server *server, struct cg_view *view);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
10
view.c
10
view.c
|
|
@ -6,8 +6,11 @@
|
||||||
* See the LICENSE file accompanying this file.
|
* See the LICENSE file accompanying this file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
#include <wlr/types/wlr_box.h>
|
#include <wlr/types/wlr_box.h>
|
||||||
#include <wlr/types/wlr_output.h>
|
#include <wlr/types/wlr_output.h>
|
||||||
|
|
@ -18,6 +21,13 @@
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
|
|
||||||
|
char *
|
||||||
|
view_get_title(struct cg_view *view)
|
||||||
|
{
|
||||||
|
const char *title = view->get_title(view);
|
||||||
|
return strndup(title, strlen(title));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
view_activate(struct cg_view *view, bool activate)
|
view_activate(struct cg_view *view, bool activate)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
2
view.h
2
view.h
|
|
@ -41,6 +41,7 @@ struct cg_view {
|
||||||
// TODO: allow applications to go to fullscreen from maximized?
|
// TODO: allow applications to go to fullscreen from maximized?
|
||||||
// struct wl_listener request_fullscreen;
|
// struct wl_listener request_fullscreen;
|
||||||
|
|
||||||
|
char *(*get_title)(struct cg_view *view);
|
||||||
void (*activate)(struct cg_view *view, bool activate);
|
void (*activate)(struct cg_view *view, bool activate);
|
||||||
void (*maximize)(struct cg_view *view, int output_width, int output_height);
|
void (*maximize)(struct cg_view *view, int output_width, int output_height);
|
||||||
void (*get_geometry)(struct cg_view *view, int *width_out, int *height_out);
|
void (*get_geometry)(struct cg_view *view, int *width_out, int *height_out);
|
||||||
|
|
@ -52,6 +53,7 @@ struct cg_view {
|
||||||
bool (*is_parent)(struct cg_view *parent, struct cg_view *child);
|
bool (*is_parent)(struct cg_view *parent, struct cg_view *child);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
char *view_get_title(struct cg_view *view);
|
||||||
void view_activate(struct cg_view *view, bool activate);
|
void view_activate(struct cg_view *view, bool activate);
|
||||||
void view_for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator, void *data);
|
void view_for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator, void *data);
|
||||||
struct wlr_surface *view_wlr_surface_at(struct cg_view *view, double sx, double sy,
|
struct wlr_surface *view_wlr_surface_at(struct cg_view *view, double sx, double sy,
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,12 @@
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
|
|
||||||
|
static char *
|
||||||
|
get_title(struct cg_view *view)
|
||||||
|
{
|
||||||
|
return view->xdg_surface->toplevel->title;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
activate(struct cg_view *view, bool activate)
|
activate(struct cg_view *view, bool activate)
|
||||||
{
|
{
|
||||||
|
|
@ -109,6 +115,7 @@ handle_xdg_shell_surface_new(struct wl_listener *listener, void *data)
|
||||||
view->destroy.notify = handle_xdg_shell_surface_destroy;
|
view->destroy.notify = handle_xdg_shell_surface_destroy;
|
||||||
wl_signal_add(&xdg_surface->events.destroy, &view->destroy);
|
wl_signal_add(&xdg_surface->events.destroy, &view->destroy);
|
||||||
|
|
||||||
|
view->get_title = get_title;
|
||||||
view->activate = activate;
|
view->activate = activate;
|
||||||
view->maximize = maximize;
|
view->maximize = maximize;
|
||||||
view->get_geometry = get_geometry;
|
view->get_geometry = get_geometry;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,12 @@
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
|
|
||||||
|
static char *
|
||||||
|
get_title(struct cg_view *view)
|
||||||
|
{
|
||||||
|
return view->xwayland_surface->title;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
activate(struct cg_view *view, bool activate)
|
activate(struct cg_view *view, bool activate)
|
||||||
{
|
{
|
||||||
|
|
@ -101,6 +107,7 @@ handle_xwayland_surface_new(struct wl_listener *listener, void *data)
|
||||||
view->destroy.notify = handle_xwayland_surface_destroy;
|
view->destroy.notify = handle_xwayland_surface_destroy;
|
||||||
wl_signal_add(&xwayland_surface->events.destroy, &view->destroy);
|
wl_signal_add(&xwayland_surface->events.destroy, &view->destroy);
|
||||||
|
|
||||||
|
view->get_title = get_title;
|
||||||
view->activate = activate;
|
view->activate = activate;
|
||||||
view->maximize = maximize;
|
view->maximize = maximize;
|
||||||
view->get_geometry = get_geometry;
|
view->get_geometry = get_geometry;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue