mirror of
https://github.com/artizirk/wdisplays.git
synced 2026-10-03 12:55:42 +03:00
Fix window not resizing to fit content, causing clipped Apply dialog
GTK3 toplevel windows on Wayland don't grow to accommodate new content once mapped, so when heads are (re)populated asynchronously after the window is shown, or when switching to the "Apply Changes?" header, the window can keep its stale (too small) size and clip the settings panel (Apply/Cancel buttons, Transform, Flipped, etc). This matches #5. - main.c: explicitly resize the window to its natural size after rebuilding the head list and after switching the header stack page. - head.ui: bound the head description label with max-width-chars so a long EDID description string can't force the layout wider than intended even when wrap/ellipsize are set.
This commit is contained in:
@@ -66,6 +66,7 @@
|
||||
<property name="wrap">True</property>
|
||||
<property name="wrap_mode">word-char</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="max_width_chars">40</property>
|
||||
<property name="xalign">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
|
||||
+21
@@ -296,6 +296,24 @@ static void queue_canvas_draw(struct wd_state *state) {
|
||||
gtk_gl_area_queue_render(GTK_GL_AREA(state->canvas));
|
||||
}
|
||||
|
||||
// GTK toplevels on Wayland don't grow to fit new content once mapped, so
|
||||
// force a resize whenever a layout change may need more space than the
|
||||
// window currently has (https://github.com/artizirk/wdisplays/issues/5).
|
||||
static void resize_to_fit(struct wd_state *state) {
|
||||
if (state->window == NULL) {
|
||||
return;
|
||||
}
|
||||
GtkRequisition natural;
|
||||
gtk_widget_get_preferred_size(state->window, NULL, &natural);
|
||||
gint cur_width, cur_height;
|
||||
gtk_window_get_size(GTK_WINDOW(state->window), &cur_width, &cur_height);
|
||||
gint new_width = MAX(cur_width, natural.width);
|
||||
gint new_height = MAX(cur_height, natural.height);
|
||||
if (new_width != cur_width || new_height != cur_height) {
|
||||
gtk_window_resize(GTK_WINDOW(state->window), new_width, new_height);
|
||||
}
|
||||
}
|
||||
|
||||
static void show_apply(struct wd_state *state) {
|
||||
const gchar *page = "title";
|
||||
if (has_changes(state)) {
|
||||
@@ -306,6 +324,7 @@ static void show_apply(struct wd_state *state) {
|
||||
}
|
||||
}
|
||||
gtk_stack_set_visible_child_name(GTK_STACK(state->header_stack), page);
|
||||
resize_to_fit(state);
|
||||
}
|
||||
|
||||
static void update_ui(WdHeadForm *form, enum wd_head_fields fields,
|
||||
@@ -350,6 +369,7 @@ void wd_ui_reset_heads(struct wd_state *state) {
|
||||
}
|
||||
update_canvas_size(state);
|
||||
queue_canvas_draw(state);
|
||||
resize_to_fit(state);
|
||||
}
|
||||
|
||||
void wd_ui_reset_head(const struct wd_head *head, enum wd_head_fields fields) {
|
||||
@@ -938,6 +958,7 @@ static void activate(GtkApplication* app, gpointer user_data) {
|
||||
GtkBuilder *builder = gtk_builder_new_from_resource(
|
||||
WDISPLAYS_RESOURCE_PREFIX "/wdisplays.ui");
|
||||
GtkWidget *window = GTK_WIDGET(gtk_builder_get_object(builder, "heads_window"));
|
||||
state->window = window;
|
||||
state->main_box = GTK_WIDGET(gtk_builder_get_object(builder, "main_box"));
|
||||
state->header_stack = GTK_WIDGET(gtk_builder_get_object(builder, "header_stack"));
|
||||
state->stack_switcher = GTK_WIDGET(gtk_builder_get_object(builder, "heads_stack_switcher"));
|
||||
|
||||
@@ -200,6 +200,7 @@ struct wd_state {
|
||||
bool panning;
|
||||
struct wd_point pan_start;
|
||||
|
||||
GtkWidget *window;
|
||||
GtkWidget *main_box;
|
||||
GtkWidget *header_stack;
|
||||
GtkWidget *stack_switcher;
|
||||
|
||||
Reference in New Issue
Block a user