Added support for percentage based window sizing
This commit is contained in:
parent
5217c5a398
commit
459de542dc
48
src/wofi.c
48
src/wofi.c
@ -401,6 +401,17 @@ static void expand(GtkExpander* expander, gpointer data) {
|
|||||||
gtk_widget_set_visible(box, !gtk_expander_get_expanded(expander));
|
gtk_widget_set_visible(box, !gtk_expander_get_expanded(expander));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void update_surface_size(void) {
|
||||||
|
if(wl != NULL) {
|
||||||
|
zwlr_layer_surface_v1_set_size(wlr_surface, width, height);
|
||||||
|
wl_surface_commit(wl_surface);
|
||||||
|
wl_display_roundtrip(wl);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_window_resize(GTK_WINDOW(window), width, height);
|
||||||
|
gtk_widget_set_size_request(scroll, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
static void widget_allocate(GtkWidget* widget, GdkRectangle* allocation, gpointer data) {
|
static void widget_allocate(GtkWidget* widget, GdkRectangle* allocation, gpointer data) {
|
||||||
(void) data;
|
(void) data;
|
||||||
if(max_height > 0) {
|
if(max_height > 0) {
|
||||||
@ -421,14 +432,8 @@ static void widget_allocate(GtkWidget* widget, GdkRectangle* allocation, gpointe
|
|||||||
} else {
|
} else {
|
||||||
max_height = allocation->height;
|
max_height = allocation->height;
|
||||||
}
|
}
|
||||||
if(wl != NULL) {
|
height = max_height * lines;
|
||||||
zwlr_layer_surface_v1_set_size(wlr_surface, width, max_height * lines);
|
update_surface_size();
|
||||||
wl_surface_commit(wl_surface);
|
|
||||||
wl_display_roundtrip(wl);
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_window_resize(GTK_WINDOW(window), width, max_height * lines);
|
|
||||||
gtk_widget_set_size_request(scroll, width, max_height * lines);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean _insert_widget(gpointer data) {
|
static gboolean _insert_widget(gpointer data) {
|
||||||
@ -1293,8 +1298,10 @@ static void get_output_pos(void* data, struct zxdg_output_v1* output, int32_t x,
|
|||||||
|
|
||||||
void wofi_init(struct map* _config) {
|
void wofi_init(struct map* _config) {
|
||||||
config = _config;
|
config = _config;
|
||||||
width = strtol(config_get(config, "width", "1000"), NULL, 10);
|
char* width_str = config_get(config, "width", "1000");
|
||||||
height = strtol(config_get(config, "height", "400"), NULL, 10);
|
char* height_str = config_get(config, "height", "400");
|
||||||
|
width = strtol(width_str, NULL, 10);
|
||||||
|
height = strtol(height_str, NULL, 10);
|
||||||
x = map_get(config, "x");
|
x = map_get(config, "x");
|
||||||
y = map_get(config, "y");
|
y = map_get(config, "y");
|
||||||
bool normal_window = strcmp(config_get(config, "normal_window", "false"), "true") == 0;
|
bool normal_window = strcmp(config_get(config, "normal_window", "false"), "true") == 0;
|
||||||
@ -1363,9 +1370,11 @@ void wofi_init(struct map* _config) {
|
|||||||
gtk_window_resize(GTK_WINDOW(window), width, height);
|
gtk_window_resize(GTK_WINDOW(window), width, height);
|
||||||
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
|
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
|
||||||
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
|
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
|
||||||
|
|
||||||
|
GdkDisplay* disp = gdk_display_get_default();
|
||||||
|
GdkWindow* gdk_win = gtk_widget_get_window(window);
|
||||||
if(!normal_window) {
|
if(!normal_window) {
|
||||||
wl_list_init(&outputs);
|
wl_list_init(&outputs);
|
||||||
GdkDisplay* disp = gdk_display_get_default();
|
|
||||||
wl = gdk_wayland_display_get_wl_display(disp);
|
wl = gdk_wayland_display_get_wl_display(disp);
|
||||||
struct wl_registry* registry = wl_display_get_registry(wl);
|
struct wl_registry* registry = wl_display_get_registry(wl);
|
||||||
struct wl_registry_listener listener = {
|
struct wl_registry_listener listener = {
|
||||||
@ -1404,7 +1413,6 @@ void wofi_init(struct map* _config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GdkWindow* gdk_win = gtk_widget_get_window(window);
|
|
||||||
gdk_wayland_window_set_use_custom_surface(gdk_win);
|
gdk_wayland_window_set_use_custom_surface(gdk_win);
|
||||||
wl_surface = gdk_wayland_window_get_wl_surface(gdk_win);
|
wl_surface = gdk_wayland_window_get_wl_surface(gdk_win);
|
||||||
|
|
||||||
@ -1417,6 +1425,22 @@ void wofi_init(struct map* _config) {
|
|||||||
wl_display_roundtrip(wl);
|
wl_display_roundtrip(wl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool width_percent = strchr(width_str, '%') != NULL;
|
||||||
|
bool height_percent = strchr(height_str, '%') != NULL;
|
||||||
|
if(width_percent || height_percent) {
|
||||||
|
GdkMonitor* monitor = gdk_display_get_monitor_at_window(disp, gdk_win);
|
||||||
|
GdkRectangle rect;
|
||||||
|
gdk_monitor_get_geometry(monitor, &rect);
|
||||||
|
if(width_percent) {
|
||||||
|
width = (width / 100.f) * rect.width;
|
||||||
|
}
|
||||||
|
if(height_percent) {
|
||||||
|
height = (height / 100.f) * rect.height;
|
||||||
|
}
|
||||||
|
update_surface_size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
outer_box = gtk_box_new(outer_orientation, 0);
|
outer_box = gtk_box_new(outer_orientation, 0);
|
||||||
gtk_widget_set_name(outer_box, "outer-box");
|
gtk_widget_set_name(outer_box, "outer-box");
|
||||||
gtk_container_add(GTK_CONTAINER(window), outer_box);
|
gtk_container_add(GTK_CONTAINER(window), outer_box);
|
||||||
|
Loading…
Reference in New Issue
Block a user