diff --git a/cagebreak.c b/cagebreak.c index 513c240..c12058f 100644 --- a/cagebreak.c +++ b/cagebreak.c @@ -6,6 +6,7 @@ #include "config.h" #include +#include #include #include #include @@ -128,17 +129,25 @@ usage(FILE *file, const char *const cage) { " -e\t\t Enable socket\n" " -h\t\t Display this help message\n" " -s\t\t Show information about the current setup and exit\n" - " -v\t\t Show the version number and exit\n", + " -v\t\t Show the version number and exit\n" + " --bs\t\t \"bad security\": Enable features with potential " + "security implications (see man page)\n", cage); } static bool parse_args(struct cg_server *server, int argc, char *argv[], char **config_path) { - int c; + int c, option_index; server->enable_socket = false; - while((c = getopt(argc, argv, "c:hvse")) != -1) { + static struct option long_options[] = {{"bs", no_argument, 0, 0}, + {0, 0, 0, 0}}; + while((c = getopt_long(argc, argv, "c:hvse", long_options, + &option_index)) != -1) { switch(c) { + case 0: + server->bs = true; + break; case 'h': usage(stdout, argv[0]); return false; @@ -275,6 +284,7 @@ main(int argc, char *argv[]) { wl_list_init(&server.output_priorities); int ret = 0; + server.bs = 0; char *config_path = NULL; if(!parse_args(&server, argc, argv, &config_path)) { diff --git a/keybinding.c b/keybinding.c index a87ab99..a4fcbef 100644 --- a/keybinding.c +++ b/keybinding.c @@ -868,10 +868,15 @@ print_view(struct cg_view *view) { struct dyn_str outp_str; outp_str.len = 0; outp_str.cur_pos = 0; - uint32_t nmemb = 4; + uint32_t nmemb = 5; outp_str.str_arr = calloc(nmemb, sizeof(char *)); print_str(&outp_str, "\"id\": %d,\n", view->id); print_str(&outp_str, "\"pid\": %d,\n", view->impl->get_pid(view)); + if(view->server->bs == true) { + char *title_str = view->impl->get_title(view); + print_str(&outp_str, "\"title\": \"%s\",\n", + title_str == NULL ? "" : title_str); + } print_str(&outp_str, "\"coords\": {\"x\":%d,\"y\":%d},\n", view->ox, view->oy); #if CG_HAS_XWAYLAND diff --git a/server.h b/server.h index 3c13c4e..9f6eca6 100644 --- a/server.h +++ b/server.h @@ -57,6 +57,7 @@ struct cg_server { struct cg_ipc_handle ipc; bool enable_socket; + bool bs; bool running; char **modes; uint16_t nws; diff --git a/view.h b/view.h index b3b2ed6..a3b61ed 100644 --- a/view.h +++ b/view.h @@ -39,6 +39,7 @@ struct cg_view { struct cg_view_impl { pid_t (*get_pid)(const struct cg_view *view); + char *(*get_title)(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); diff --git a/xdg_shell.c b/xdg_shell.c index 164ede0..afa3352 100644 --- a/xdg_shell.c +++ b/xdg_shell.c @@ -110,6 +110,13 @@ get_pid(const struct cg_view *view) { return pid; } +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 bool is_primary(const struct cg_view *view) { const struct cg_xdg_shell_view *xdg_shell_view = @@ -208,6 +215,7 @@ handle_xdg_shell_surface_destroy(struct wl_listener *listener, void *_data) { } static const struct cg_view_impl xdg_shell_view_impl = {.get_pid = get_pid, + .get_title = get_title, .is_primary = is_primary, .activate = activate, diff --git a/xwayland.c b/xwayland.c index fd8d174..ece9e5a 100644 --- a/xwayland.c +++ b/xwayland.c @@ -46,6 +46,13 @@ get_pid(const struct cg_view *view) { return surf->pid; } +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 bool is_primary(const struct cg_view *view) { const struct cg_xwayland_view *xwayland_view = @@ -157,6 +164,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,