Add bs option

This commit is contained in:
project-repo 2023-03-06 17:41:36 +01:00
commit 0c0e9aa083
6 changed files with 37 additions and 4 deletions

View file

@ -6,6 +6,7 @@
#include "config.h"
#include <fontconfig/fontconfig.h>
#include <getopt.h>
#include <pango.h>
#include <pango/pangocairo.h>
#include <signal.h>
@ -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)) {

View file

@ -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

View file

@ -57,6 +57,7 @@ struct cg_server {
struct cg_ipc_handle ipc;
bool enable_socket;
bool bs;
bool running;
char **modes;
uint16_t nws;

1
view.h
View file

@ -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);

View file

@ -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,

View file

@ -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,