-
-
Notifications
You must be signed in to change notification settings - Fork 61
Widgets: Create Granite.Application
#877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||
| * Copyright 2025 elementary, Inc. (https://elementary.io) | ||||||||||||||||||||||||
| * SPDX-License-Identifier: GPL-2.0-or-later | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure we use LGPL-3.0-or-later in granite. |
||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * A {@link Gtk.Application} subclass that includes Granite initialization and | ||||||||||||||||||||||||
| * setup for common accelerator actions. | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * @since 7.7.0 | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| [Version (since = "7.7.0")] | ||||||||||||||||||||||||
| public class Granite.Application : Gtk.Application { | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| public Application () { | ||||||||||||||||||||||||
| Object ( | ||||||||||||||||||||||||
| flags: ApplicationFlags.DEFAULT_FLAGS | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+16
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Otherwise, it has no use for us in the vala side of the things. |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| construct { | ||||||||||||||||||||||||
| Intl.setlocale (LocaleCategory.ALL, ""); | ||||||||||||||||||||||||
| Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); | ||||||||||||||||||||||||
| Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); | ||||||||||||||||||||||||
| Intl.textdomain (GETTEXT_PACKAGE); | ||||||||||||||||||||||||
|
Comment on lines
+23
to
+26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it looks like init does handle some of this already: Line 30 in 66c5fec
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| public override void startup () { | ||||||||||||||||||||||||
| Granite.init (); | ||||||||||||||||||||||||
| base.startup (); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Respond to user theme preferences | ||||||||||||||||||||||||
| var granite_settings = Granite.Settings.get_default (); | ||||||||||||||||||||||||
| var gtk_settings = Gtk.SEttings.get_default (); | ||||||||||||||||||||||||
|
Comment on lines
+34
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Little typo, also thoses objects are unowned.
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
Comment on lines
+37
to
+45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ()
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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* 😓 |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Set up common actions | ||||||||||||||||||||||||
| var quit_action = new SimpleAction ("quit", null); | ||||||||||||||||||||||||
| add_action (quit_action); | ||||||||||||||||||||||||
| set_accels_for_action ("app.quit", {"<Control>q"}); | ||||||||||||||||||||||||
| quit_action.activate.connect (quit); | ||||||||||||||||||||||||
|
Comment on lines
+48
to
+51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
There was a problem hiding this comment.
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.