Skip to content

Conversation

@wpkelso
Copy link
Member

@wpkelso wpkelso commented Jun 19, 2025

Moves some common boilerplate code to a Gtk.Application subclass so developers get it for free.

  • Themeing compliance
  • Quit action & accel
  • Granite initialization
  • I18n initialization

@wpkelso wpkelso linked an issue Jun 19, 2025 that may be closed by this pull request
Copy link
Contributor

@Marukesu Marukesu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of having an Application class, but i think the boilerplate for elementary applications is minimal enough to not worth the addition. if we have more features than theme and the unity badge support (that not many elementary apps make use that i known of) ready to be merged, then it's start to being considerable. Note that, granite used to have an Application class, but got deprecated and replaced with the current Granite.Service.Application namespace.

We also would want to make most applications class make use of what Gtk.Application already provide us with before setling in what we need to provide. Like, the quit action implemented here would break code, terminal, and files; as they support multiple windows and need to manage they state before quit. But we also need to check if we can move that management to the shutdown signal. If so, then the quit action that is currently implemented here works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and Granite.Services.Application should be merged, also Application classes aren't widgets, so this file should be direct at the src folder.

@@ -0,0 +1,53 @@
/*
* Copyright 2025 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-2.0-or-later
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure we use LGPL-3.0-or-later in granite.

Comment on lines +16 to +20
public Application () {
Object (
flags: ApplicationFlags.DEFAULT_FLAGS
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public constructors, in this case, is only for the use of procedural code (i.e., c and rust bindings). So this should take the application_id and flags as parameters.

Suggested change
public Application () {
Object (
flags: ApplicationFlags.DEFAULT_FLAGS
);
}
public Application (string? application_id, GLib.ApplicationFlags flags) {
Object (
application_id: application_id,
flags: flags
);
}

Otherwise, it has no use for us in the vala side of the things.

Comment on lines +23 to +26
Intl.setlocale (LocaleCategory.ALL, "");
Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
Intl.textdomain (GETTEXT_PACKAGE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Granite.init() should be handling this already, also, we don't have any granite specific command line argument to this be executed before startup() anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it looks like init does handle some of this already:

GLib.Intl.bindtextdomain (Granite.GETTEXT_PACKAGE, Granite.LOCALEDIR);

Comment on lines +37 to +45
gtk_settings.gtk_application_prefer_dark_theme = (
granite_settings.prefers_color_scheme == DARK
);

granite_settings.noftify["prefers-color-scheme"].connect (() => {
gtk_settings.gtk_application_prefer_dark_theme = (
granite_settings.prefers_color_scheme == DARK
);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to handling this here, we need a property that controls the "no-preference" behavior between default dark and default bright applications.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually already handle this in StyleManager as well. I think that's automatically added in Granite.init ()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, the flatpak SDK doesn't have the 7.7.0 stuff, so my boilerplate reference code is old* 😓

Comment on lines +48 to +51
var quit_action = new SimpleAction ("quit", null);
add_action (quit_action);
set_accels_for_action ("app.quit", {"<Control>q"});
quit_action.activate.connect (quit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Application actions can be activated from external applications after added, so we need to have it completely setup before adding it.

Suggested change
var quit_action = new SimpleAction ("quit", null);
add_action (quit_action);
set_accels_for_action ("app.quit", {"<Control>q"});
quit_action.activate.connect (quit);
var quit_action = new SimpleAction ("quit", null);
quit_action.activate.connect (quit);
add_action (quit_action);
set_accels_for_action ("app.quit", {"<Control>q"});

Comment on lines +34 to +35
var granite_settings = Granite.Settings.get_default ();
var gtk_settings = Gtk.SEttings.get_default ();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little typo, also thoses objects are unowned.

Suggested change
var granite_settings = Granite.Settings.get_default ();
var gtk_settings = Gtk.SEttings.get_default ();
unowned var granite_settings = Granite.Settings.get_default ();
unowned var gtk_settings = Gtk.Settings.get_default ();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide a Gtk.Application and Gtk.ApplicationWindow subclass

5 participants