Skip to content

Commit

Permalink
Port to Gtk4 (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Jul 29, 2024
1 parent a45a6ba commit d28aef5
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 122 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ jobs:
with:
platforms: arm64

- name: Install Rust SDK extension
run: |
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak install -y --arch=${{matrix.arch}} org.freedesktop.Sdk.Extension.rust-stable//23.08
- name: Build
uses: flatpak/flatpak-github-actions/flatpak-builder@v6
with:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ jobs:
with:
platforms: arm64

- name: Install Rust SDK extension
run: |
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak install -y --arch=${{matrix.arch}} org.freedesktop.Sdk.Extension.rust-stable//23.08
- name: Build
uses: flatpak/flatpak-github-actions/flatpak-builder@v6
with:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ jobs:
with:
platforms: arm64

- name: Install Rust SDK extension
run: |
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak install -y --arch=${{matrix.arch}} org.freedesktop.Sdk.Extension.rust-stable//23.08
- name: Build
uses: flatpak/flatpak-github-actions/flatpak-builder@v6
with:
Expand Down
4 changes: 4 additions & 0 deletions data/Application.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
border-right-width: 0;
padding-right: 0;
}

picture {
background: black;
}
21 changes: 13 additions & 8 deletions data/io.elementary.camera.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
<summary>The mode of the camera, photo or video</summary>
<description>Photo mode is represented by 0, video mode by 1</description>
</key>
<key name="window-maximized" type="b">
<default>false</default>
<summary>Whether the window was maximized on last run</summary>
<description>Whether the window was maximized on last run</description>
<key name="window-height" type="i">
<default>768</default>
<summary>Most recent window height</summary>
<description>Most recent window height</description>
</key>
<key name="window-width" type="i">
<default>918</default>
<summary>Most recent window width</summary>
<description>Most recent window width</description>
</key>
<key name="window-size" type="(ii)">
<default>(918, 768)</default>
<summary>Most recent window size (height, width)</summary>
<description>Most recent window size (height, width)</description>
<key name="window-maximized" type="b">
<default>false</default>
<summary>Open window maximized</summary>
<description>Whether the main window of the application should open maximized or not.</description>
</key>
</schema>
</schemalist>
30 changes: 30 additions & 0 deletions io.elementary.camera.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ runtime: io.elementary.Platform
runtime-version: '8'
sdk: io.elementary.Sdk
command: io.elementary.camera
sdk-extensions:
- "org.freedesktop.Sdk.Extension.rust-stable"
build-options:
env:
CARGO_HOME: /run/build/cargo-c/cargo
append-path: /usr/lib/sdk/rust-stable/bin
finish-args:
- '--filesystem=xdg-pictures'
- '--filesystem=xdg-videos'
Expand All @@ -11,13 +17,37 @@ finish-args:
- '--socket=fallback-x11'
- '--socket=wayland'
- '--socket=pulseaudio'
- '--device=dri'
- '--device=all'
- '--env=GST_PLUGIN_PATH_1_0=/app/lib64/gstreamer-1.0'

- '--metadata=X-DConf=migrate-path=/io/elementary/camera/'
cleanup:
- '*.a'
- '*.la'
modules:
- name: cargo-c
buildsystem: simple
build-commands:
- "cargo install cargo-c --root /app"
build-options:
build-args:
- "--share=network"
cleanup:
- "*"

- name: gst-plugins-rs
buildsystem: simple
sources:
- type: git
url: https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs
branch: '0.12'
build-options:
build-args:
- "--share=network"
build-commands:
- "cargo cinstall -p gst-plugin-gtk4 --prefix=/app"

- name: canberra
config-opts:
- '--enable-gstreamer'
Expand Down
5 changes: 2 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ executable(
dependency('gee-0.8'),
dependency('gio-2.0'),
dependency('glib-2.0'),
dependency('granite', version: '>=6.0.0'),
dependency('gtk+-3.0'),
dependency('granite-7', version: '>=7.2.0'),
dependency('gtk4'),
dependency('libcanberra'),
dependency('libhandy-1', version: '>=0.90.0'),
meson.get_compiler('vala').find_library('posix')
],
install : true
Expand Down
27 changes: 11 additions & 16 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,43 @@ public class Camera.Application : Gtk.Application {

public override void startup () {
base.startup ();
Hdy.init ();
Granite.init ();

var quit_action = new SimpleAction ("quit", null);
quit_action.activate.connect (quit);
add_action (quit_action);

set_accels_for_action ("app.quit", {"<Control>q"});

var application_provider = new Gtk.CssProvider ();
application_provider.load_from_resource (resource_base_path + "/Application.css");
Gtk.StyleContext.add_provider_for_screen (
Gdk.Screen.get_default (),
application_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
);

var granite_settings = Granite.Settings.get_default ();
var gtk_settings = Gtk.Settings.get_default ();

gtk_settings.gtk_application_prefer_dark_theme =
granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
granite_settings.prefers_color_scheme == DARK;

granite_settings.notify["prefers-color-scheme"].connect (() => {
gtk_settings.gtk_application_prefer_dark_theme =
granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
granite_settings.prefers_color_scheme == DARK;
});
}

protected override void activate () {
if (active_window == null) {
var main_window = new MainWindow (this);

int width, height;
settings.get ("window-size", "(ii)", out width, out height);

main_window.resize (width, height);
/*
* This is very finicky. Bind size after present else set_titlebar gives us bad sizes
* Set maximize after height/width else window is min size on unmaximize
* Bind maximize as SET else get get bad sizes
*/
settings.bind ("window-height", main_window, "default-height", DEFAULT);
settings.bind ("window-width", main_window, "default-width", DEFAULT);

if (settings.get_boolean ("window-maximized")) {
main_window.maximize ();
}

settings.bind ("window-maximized", main_window, "is-maximized", SET);
settings.bind ("window-maximized", main_window, "maximized", SET);
}

active_window.present ();
Expand Down
Loading

0 comments on commit d28aef5

Please sign in to comment.