aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>2021-03-30 13:56:01 +0200
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>2021-03-30 16:55:33 +0200
commit994bee69b165bcd2dff13f646548ae43f2a3c704 (patch)
treed821e14e9f61614727c6e465746e860244f364c0
parent1a76000d06c955471e8c3022d471adcee71cd6ac (diff)
Allow expanding the window with Gtk3
It is nice to be able to expand the window in real time. Add support for it with Gtk3. Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
-rw-r--r--data/camorama-gtk3.ui30
-rw-r--r--src/callbacks.c36
-rw-r--r--src/callbacks.h1
-rw-r--r--src/camorama-window.c7
4 files changed, 60 insertions, 14 deletions
diff --git a/data/camorama-gtk3.ui b/data/camorama-gtk3.ui
index c0f7593..826fb59 100644
--- a/data/camorama-gtk3.ui
+++ b/data/camorama-gtk3.ui
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.22.0 -->
+<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkAccelGroup" id="accelgroup1"/>
@@ -46,6 +46,9 @@
<group name="accelgroup1"/>
</accel-groups>
<signal name="delete-event" handler="gtk_main_quit" swapped="no"/>
+ <child type="titlebar">
+ <placeholder/>
+ </child>
<child>
<object class="GtkBox" id="vbox36">
<property name="visible">True</property>
@@ -149,7 +152,6 @@
</child>
<child>
<object class="GtkMenuItem" id="change_camera">
- <property name="visible">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Change Camera</property>
<property name="use_underline">True</property>
@@ -215,6 +217,8 @@
<object class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
@@ -223,13 +227,16 @@
<property name="height_request">240</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="double_buffered">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
<signal name="draw" handler="show_buffer" swapped="no"/>
</object>
</child>
</object>
<packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
@@ -659,15 +666,15 @@
</child>
</object>
</child>
- <child type="titlebar">
- <placeholder/>
- </child>
</object>
<object class="GtkDialog" id="prefswindow">
<property name="can_focus">False</property>
<property name="resizable">False</property>
<property name="type_hint">dialog</property>
<property name="transient_for">main_window</property>
+ <child type="titlebar">
+ <placeholder/>
+ </child>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="visible">True</property>
@@ -1819,9 +1826,6 @@
<action-widget response="-11">helpbutton1</action-widget>
<action-widget response="-7">okbutton1</action-widget>
</action-widgets>
- <child type="titlebar">
- <placeholder/>
- </child>
</object>
<object class="GtkDialog" id="videodev_window">
<property name="can_focus">False</property>
@@ -1830,6 +1834,9 @@
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
<property name="transient_for">main_window</property>
+ <child type="titlebar">
+ <placeholder/>
+ </child>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
@@ -1900,8 +1907,5 @@
</child>
</object>
</child>
- <child type="titlebar">
- <placeholder/>
- </child>
</object>
</interface>
diff --git a/src/callbacks.c b/src/callbacks.c
index 336e13d..b97bead 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -394,6 +394,42 @@ void set_image_scale(cam_t *cam)
g_settings_set_int(cam->gc, CAM_SETTINGS_HEIGHT, cam->height);
}
+gboolean on_configure_event(GtkMenuItem *menuitem, GdkEvent *event, cam_t *cam)
+{
+#if GTK_MAJOR_VERSION >= 3
+ GtkWidget *da = GTK_WIDGET(gtk_builder_get_object(cam->xml, "da"));
+ gint width, height;
+ gchar *title;
+ double scale;
+
+ gtk_window_get_size(GTK_WINDOW(GTK_WIDGET(gtk_builder_get_object(cam->xml, "main_window"))), &width, &height);
+
+ width = gtk_widget_get_allocated_width(da);
+ height = gtk_widget_get_allocated_height(da);
+
+ scale = 1. * width / cam->width;
+ if (1. * height / cam->height < scale)
+ scale = 1. * height / cam->height;
+
+ if (scale > 0 && scale <= 1.)
+ cam->scale = scale;
+ if (scale > 1.)
+ cam->scale = 1.;
+
+ if (cam->scale == (float)1.)
+ title = g_strdup_printf("Camorama - %s - %dx%d", cam->name,
+ cam->width, cam->height);
+ else
+ title = g_strdup_printf("Camorama - %s - %dx%d (scale: %d%%)", cam->name,
+ cam->width, cam->height, (int)(cam->scale * 100.f));
+ gtk_window_set_title(GTK_WINDOW(GTK_WIDGET(gtk_builder_get_object(cam->xml, "main_window"))),
+ title);
+ g_free(title);
+#endif
+
+ return FALSE;
+}
+
void on_change_size_activate(GtkWidget *widget, cam_t *cam)
{
gchar const *name;
diff --git a/src/callbacks.h b/src/callbacks.h
index 6d1eb2f..4f11587 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -17,6 +17,7 @@ G_BEGIN_DECLS
void on_change_size_activate(GtkWidget * widget, cam_t *cam);
void on_quit_activate(GtkMenuItem *menuitem, cam_t *cam);
+gboolean on_configure_event(GtkMenuItem *menuitem, GdkEvent *event, cam_t *cam);
int delete_event(GtkWidget *, gpointer data);
void cap_func(GtkWidget *, cam_t *);
void rcap_func(GtkWidget *, cam_t *);
diff --git a/src/camorama-window.c b/src/camorama-window.c
index 21fefc7..337032f 100644
--- a/src/camorama-window.c
+++ b/src/camorama-window.c
@@ -360,7 +360,6 @@ void load_interface(cam_t *cam)
// Ensure that windows will be resized due to the controls
gtk_window_resize(GTK_WINDOW(window), 320, 240);
-
/* buttons */
g_signal_connect(gtk_builder_get_object(cam->xml, "quit"), "activate",
G_CALLBACK(on_quit_activate), cam);
@@ -511,4 +510,10 @@ void load_interface(cam_t *cam)
set_sensitive(cam);
gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object(cam->xml, "string_entry")),
cam->usestring);
+
+ // Detect window resize calls
+#if GTK_MAJOR_VERSION >= 3
+ g_signal_connect(window,
+ "configure-event", G_CALLBACK(on_configure_event), cam);
+#endif
}

Privacy Policy