[gnome-builder/wip/gtk4-port] plugins/meson-templates: inherit AdwApplicationWindow



commit 63f201ebfba03638c492ab69a5fa8cba7228980e
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jun 7 20:13:24 2022 -0700

    plugins/meson-templates: inherit AdwApplicationWindow
    
    If using libadwaita, inherit from AdwApplicationWindow instead.
    
    Clearly this all points out that we need a way to add patterns to an
    application eventually.

 .../meson-templates/resources/src/window-gtk4.py   |  6 ++--
 .../meson-templates/resources/src/window-gtk4.rs   | 10 ++++--
 .../meson-templates/resources/src/window-gtk4.ui   | 36 ++++++++++++++++++++--
 .../meson-templates/resources/src/window-gtk4.vala |  2 +-
 src/plugins/meson-templates/resources/src/window.c |  4 +--
 src/plugins/meson-templates/resources/src/window.h |  6 +++-
 6 files changed, 53 insertions(+), 11 deletions(-)
---
diff --git a/src/plugins/meson-templates/resources/src/window-gtk4.py 
b/src/plugins/meson-templates/resources/src/window-gtk4.py
index b8065c27e..a41beaa94 100644
--- a/src/plugins/meson-templates/resources/src/window-gtk4.py
+++ b/src/plugins/meson-templates/resources/src/window-gtk4.py
@@ -1,10 +1,12 @@
 {{include "license.py"}}
 
+{{if is_adwaita}}
+from gi.repository import Adw
+{{end}}
 from gi.repository import Gtk
 
-
 @Gtk.Template(resource_path='{{appid_path}}/{{ui_file}}')
-class {{PreFix}}Window(Gtk.ApplicationWindow):
+class {{PreFix}}Window({{if is_adwaita}}Adw{{else}}Gtk{{end}}.ApplicationWindow):
     __gtype_name__ = '{{PreFix}}Window'
 
     label = Gtk.Template.Child()
diff --git a/src/plugins/meson-templates/resources/src/window-gtk4.rs 
b/src/plugins/meson-templates/resources/src/window-gtk4.rs
index 0ef2d37c2..1237231d3 100644
--- a/src/plugins/meson-templates/resources/src/window-gtk4.rs
+++ b/src/plugins/meson-templates/resources/src/window-gtk4.rs
@@ -1,3 +1,6 @@
+{{if is_adwaita}}
+use adw::subclass::prelude::*;
+{{end}}
 use gtk::prelude::*;
 use gtk::subclass::prelude::*;
 use gtk::{gio, glib, CompositeTemplate};
@@ -19,7 +22,7 @@ mod imp {
     impl ObjectSubclass for {{PreFix}}Window {
         const NAME: &'static str = "{{PreFix}}Window";
         type Type = super::{{PreFix}}Window;
-        type ParentType = gtk::ApplicationWindow;
+        type ParentType = {{if is_adwaita}}adw{{else}}gtk{{end}}::ApplicationWindow;
 
         fn class_init(klass: &mut Self::Class) {
             Self::bind_template(klass);
@@ -34,11 +37,14 @@ mod imp {
     impl WidgetImpl for {{PreFix}}Window {}
     impl WindowImpl for {{PreFix}}Window {}
     impl ApplicationWindowImpl for {{PreFix}}Window {}
+{{if is_adwaita}}
+    impl AdwApplicationWindowImpl for {{Prefix}}Window {}
+{{end}}
 }
 
 glib::wrapper! {
     pub struct {{PreFix}}Window(ObjectSubclass<imp::{{PreFix}}Window>)
-        @extends gtk::Widget, gtk::Window, gtk::ApplicationWindow,
+        @extends gtk::Widget, gtk::Window, gtk::ApplicationWindow,{{if is_adwaita}} 
adw::ApplicationWindow,{{end}}
         @implements gio::ActionGroup, gio::ActionMap;
 }
 
diff --git a/src/plugins/meson-templates/resources/src/window-gtk4.ui 
b/src/plugins/meson-templates/resources/src/window-gtk4.ui
index f9a03a124..2163ba420 100644
--- a/src/plugins/meson-templates/resources/src/window-gtk4.ui
+++ b/src/plugins/meson-templates/resources/src/window-gtk4.ui
@@ -1,9 +1,39 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk" version="4.0"/>
-  <template class="{{PreFix}}Window" parent="GtkApplicationWindow">
+{{if is_adwaita}}
+  <requires lib="Adw" version="1.0"/>
+{{end}}
+  <template class="{{PreFix}}Window" parent="{{if is_adwaita}}Adw{{else}}Gtk{{end}}ApplicationWindow">
     <property name="default-width">600</property>
     <property name="default-height">300</property>
+{{if is_adwaita}}
+    <child>
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkHeaderBar" id="header_bar">
+            <child type="end">
+              <object class="GtkMenuButton">
+                <property name="icon-name">open-menu-symbolic</property>
+                <property name="menu-model">primary_menu</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label">
+            <property name="label">Hello, World!</property>
+            <property name="vexpand">true</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+              <attribute name="scale" value="2"/>
+            </attributes>
+          </object>
+        </child>
+      </object>
+    </child>
+{{else}}
     <child type="titlebar">
       <object class="GtkHeaderBar" id="header_bar">
         <child type="end">
@@ -23,8 +53,8 @@
         </attributes>
       </object>
     </child>
+{{end}}
   </template>
-
   <menu id="primary_menu">
     <section>
       <item>
@@ -36,7 +66,7 @@
         <attribute name="action">win.show-help-overlay</attribute>
       </item>
       <item>
-        <attribute name="label" translatable="yes">_About {{name}}</attribute>
+        <attribute name="label" translatable="yes">_About {{Title}}</attribute>
         <attribute name="action">app.about</attribute>
       </item>
     </section>
diff --git a/src/plugins/meson-templates/resources/src/window-gtk4.vala 
b/src/plugins/meson-templates/resources/src/window-gtk4.vala
index 4cacdb12f..226d1c5ff 100644
--- a/src/plugins/meson-templates/resources/src/window-gtk4.vala
+++ b/src/plugins/meson-templates/resources/src/window-gtk4.vala
@@ -2,7 +2,7 @@
 
 namespace {{PreFix}} {
     [GtkTemplate (ui = "{{appid_path}}/{{ui_file}}")]
-    public class Window : Gtk.ApplicationWindow {
+    public class Window : {{if is_adwaita}}Adw{{else}}Gtk{{end}}.ApplicationWindow {
         [GtkChild]
         private unowned Gtk.Label label;
 
diff --git a/src/plugins/meson-templates/resources/src/window.c 
b/src/plugins/meson-templates/resources/src/window.c
index 689d03968..21a10f8fe 100644
--- a/src/plugins/meson-templates/resources/src/window.c
+++ b/src/plugins/meson-templates/resources/src/window.c
@@ -5,14 +5,14 @@
 
 struct _{{PreFix}}Window
 {
-  GtkApplicationWindow  parent_instance;
+  {{if is_adwaita}}Adw{{else}}Gtk{{end}}ApplicationWindow  parent_instance;
 
   /* Template widgets */
   GtkHeaderBar        *header_bar;
   GtkLabel            *label;
 };
 
-G_DEFINE_TYPE ({{PreFix}}Window, {{prefix_}}_window, GTK_TYPE_APPLICATION_WINDOW)
+G_DEFINE_FINAL_TYPE ({{PreFix}}Window, {{prefix_}}_window, {{if 
is_adwaita}}ADW{{else}}GTK{{end}}_TYPE_APPLICATION_WINDOW)
 
 static void
 {{prefix_}}_window_class_init ({{PreFix}}WindowClass *klass)
diff --git a/src/plugins/meson-templates/resources/src/window.h 
b/src/plugins/meson-templates/resources/src/window.h
index 3e757b50f..6ba8f3f5c 100644
--- a/src/plugins/meson-templates/resources/src/window.h
+++ b/src/plugins/meson-templates/resources/src/window.h
@@ -2,12 +2,16 @@
 
 #pragma once
 
+{{if is_adwaita}}
+#include <adwaita.h>
+{{else}}
 #include <gtk/gtk.h>
+{{end}}
 
 G_BEGIN_DECLS
 
 #define {{PREFIX}}_TYPE_WINDOW ({{prefix_}}_window_get_type())
 
-G_DECLARE_FINAL_TYPE ({{PreFix}}Window, {{prefix_}}_window, {{PREFIX}}, WINDOW, GtkApplicationWindow)
+G_DECLARE_FINAL_TYPE ({{PreFix}}Window, {{prefix_}}_window, {{PREFIX}}, WINDOW, {{if 
is_adwaita}}Adw{{else}}Gtk{{end}}ApplicationWindow)
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]