Skip to content

Commit

Permalink
Port to GTK 4 (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Mar 13, 2024
1 parent 298636d commit 20156e1
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gettext.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Gettext Updates

on:
push:
branches: [master]
branches: [main]

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install Dependencies
run: |
apt update
apt install -y libgranite-dev libgtk-3-dev libswitchboard-2.0-dev libwacom-dev libgudev-1.0-dev libx11-dev libxi-dev meson valac
apt install -y libgranite-7-dev libgtk-4-dev libswitchboard-3-dev libwacom-dev libgudev-1.0-dev libx11-dev libxi-dev meson valac
- name: Build
env:
DESTDIR: out
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Release

on:
pull_request:
branches: [master]
branches: [main]
types: [closed]
jobs:
release:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Switchboard Wacom Plug
# Wacom Settings
[![Translation status](https://l10n.elementary.io/widgets/switchboard/-/plug-wacom/svg-badge.svg)](https://l10n.elementary.io/engage/switchboard/?utm_source=widget)

![screenshot](data/screenshot.png?raw=true)
Expand All @@ -7,8 +7,8 @@

You'll need the following dependencies:

* libswitchboard-2.0-dev
* libgranite-dev
* libswitchboard-3-dev
* libgranite-7-dev
* libwacom-dev
* libgudev-1.0-dev
* libx11-dev
Expand Down
4 changes: 2 additions & 2 deletions data/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
i18n.merge_file(
input: 'io.elementary.switchboard.wacom.appdata.xml.in',
output: 'io.elementary.switchboard.wacom.appdata.xml',
input: 'wacom.metainfo.xml.in',
output: 'io.elementary.settings.wacom.metainfo.xml',
po_dir: join_paths(meson.source_root (), 'po', 'extra'),
install_dir: join_paths(datadir, 'metainfo'),
install: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="addon">
<id>io.elementary.switchboard.wacom</id>
<extends>io.elementary.switchboard</extends>
<id>io.elementary.settings.wacom</id>
<extends>io.elementary.settings</extends>
<name>Wacom Settings</name>
<summary>Configure Wacom tablets</summary>
<icon type="stock">input-tablet</icon>
<translation type="gettext">wacom</translation>
<translation type="gettext">io.elementary.settings.wacom</translation>
<releases>
<release version="1.0.1" date="2022-07-03" urgency="medium">
<description>
Expand All @@ -23,7 +23,7 @@
</releases>
<screenshots>
<screenshot type="default">
<image>https://raw.githubusercontent.com/elementary/switchboard-plug-wacom/master/data/screenshot-general.png</image>
<image>https://raw.githubusercontent.com/elementary/switchboard-plug-wacom/main/data/screenshot-general.png</image>
</screenshot>
</screenshots>
<url type="homepage">https://elementary.io</url>
Expand Down
4 changes: 2 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project(
vapi_dir = join_paths(meson.current_source_dir(), 'vapi')
add_project_arguments(['--vapidir', vapi_dir], language: 'vala')

gettext_name = meson.project_name() + '-plug'
gettext_name = 'io.elementary.settings.' + meson.project_name()
gnome = import('gnome')
i18n = import('i18n')

Expand All @@ -22,7 +22,7 @@ add_project_arguments(

config_data = configuration_data()
config_data.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
config_data.set_quoted('GETTEXT_PACKAGE', meson.project_name() + '-plug')
config_data.set_quoted('GETTEXT_PACKAGE', gettext_name)
config_file = configure_file(
input: 'src/Config.vala.in',
output: '@BASENAME@',
Expand Down
4 changes: 2 additions & 2 deletions src/Backend/DeviceManagerWayland.vala
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ public class Wacom.Backend.DeviceManagerWayland : DeviceManager {
}

public override Device? lookup_gdk_device (Gdk.Device device) {
if (!(device is GdkWayland.Device)) {
if (!(device is Gdk.Wayland.Device)) {
return null;
}

var node_path = (device as GdkWayland.Device).get_node_path ();
var node_path = (device as Gdk.Wayland.Device).get_node_path ();
if (node_path == null) {
return null;
}
Expand Down
30 changes: 10 additions & 20 deletions src/Backend/DeviceManagerX11.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,16 @@ public class Wacom.Backend.DeviceManagerX11 : DeviceManager {
seat.device_added.connect (add_device);
seat.device_removed.connect (remove_device);

var devices = seat.get_slaves (Gdk.SeatCapabilities.ALL);
var devices = seat.get_devices (Gdk.SeatCapabilities.ALL);
foreach (var device in devices) {
add_device (device);
}
}

private void add_device (Gdk.Device gdk_device) {
if (gdk_device.type == Gdk.DeviceType.MASTER) {
return;
}

int id = -1;
if (gdk_device is Gdk.X11.DeviceXI2) {
id = (gdk_device as Gdk.X11.DeviceXI2).device_id;
} else {
id = Gdk.X11.device_get_id ((Gdk.X11.DeviceCore)gdk_device);
id = ((Gdk.X11.DeviceXI2) gdk_device).device_id;
}

if (id == -1) {
Expand Down Expand Up @@ -82,8 +76,6 @@ public class Wacom.Backend.DeviceManagerX11 : DeviceManager {
case Gdk.InputSource.TRACKPOINT:
return Wacom.Backend.Device.DeviceType.MOUSE;
case Gdk.InputSource.PEN:
case Gdk.InputSource.ERASER:
case Gdk.InputSource.CURSOR:
if (device.name.contains ("pad")) {
return Wacom.Backend.Device.DeviceType.TABLET | Wacom.Backend.Device.DeviceType.PAD;
}
Expand Down Expand Up @@ -114,18 +106,18 @@ public class Wacom.Backend.DeviceManagerX11 : DeviceManager {
private static string? get_xdevice_node (int id) {
Gdk.Display.get_default ().sync ();

unowned X.Display display = Gdk.X11.get_default_xdisplay ();
var prop = display.intern_atom ("Device Node", false);
unowned var display = (Gdk.X11.Display) Gdk.Display.get_default ();
var prop = display.get_xatom_by_name ("Device Node");

X.Atom act_type;
int act_format;
ulong n_items, bytes_after;
void* data;

Gdk.error_trap_push ();
display.error_trap_push ();

var ret = XI2.get_property (
display,
display.get_xdisplay (),
id,
prop,
0,
Expand All @@ -140,11 +132,11 @@ public class Wacom.Backend.DeviceManagerX11 : DeviceManager {
);

if (ret != X.Success) {
Gdk.error_trap_pop_ignored ();
display.error_trap_pop_ignored ();
return null;
}

if (Gdk.error_trap_pop () != 0) {
if (display.error_trap_pop () != 0) {
return null;
}

Expand Down Expand Up @@ -188,9 +180,7 @@ public class Wacom.Backend.DeviceManagerX11 : DeviceManager {

int id = -1;
if (device is Gdk.X11.DeviceXI2) {
id = (device as Gdk.X11.DeviceXI2).device_id;
} else {
id = Gdk.X11.device_get_id ((Gdk.X11.DeviceCore)device);
id = ((Gdk.X11.DeviceXI2) device).device_id;
}

var display = device.get_display () as Gdk.X11.Display;
Expand All @@ -199,7 +189,7 @@ public class Wacom.Backend.DeviceManagerX11 : DeviceManager {
var ret = XI2.get_property (
display.get_xdisplay (),
id,
Gdk.X11.get_xatom_by_name_for_display (display, "Wacom Tool Type"),
display.get_xatom_by_name ("Wacom Tool Type"),
0,
1,
false,
Expand Down
2 changes: 1 addition & 1 deletion src/Backend/WacomToolMap.vala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class Wacom.Backend.WacomToolMap : GLib.Object {
}

private void load_keyfiles () {
var dir = Path.build_filename (Environment.get_user_cache_dir (), "io.elementary.switchboard", "wacom");
var dir = Path.build_filename (Environment.get_user_cache_dir (), "io.elementary.settings", "wacom");

if (DirUtils.create_with_parents (dir, 0700) < 0) {
warning ("Could not create directory '%s', stylus mapping may not work well", dir);
Expand Down
50 changes: 20 additions & 30 deletions src/MainPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* SPDX-FileCopyrightText: 2019-2024 elementary, Inc. (https://elementary.io)
*/

public class Wacom.MainPage : Granite.SimpleSettingsPage {
public class Wacom.MainPage : Switchboard.SettingsPage {
private Backend.DeviceManager device_manager;
private Backend.WacomTool? last_stylus = null;

private Backend.WacomToolMap tool_map;

private Granite.Widgets.AlertView placeholder;
private Granite.Placeholder placeholder;
private Gtk.Box main_box;
private Gtk.Stack stack;
private Gtk.Stack stylus_stack;
Expand All @@ -20,47 +20,37 @@ public class Wacom.MainPage : Granite.SimpleSettingsPage {
public MainPage () {
Object (
title: _("Wacom"),
icon_name: "input-tablet"
icon: new ThemedIcon ("input-tablet")
);
}

construct {
tool_map = Backend.WacomToolMap.get_default ();

placeholder = new Granite.Widgets.AlertView (
_("No Tablets Available"),
_("Please ensure your tablet is connected and switched on"),
""
);
placeholder.get_style_context ().remove_class (Gtk.STYLE_CLASS_VIEW);
placeholder.show_all ();
placeholder = new Granite.Placeholder (_("No Tablets Available")) {
description = _("Please ensure your tablet is connected and switched on")
};

var stylus_placeholder = new Granite.Widgets.AlertView (
_("No Stylus Detected"),
_("Move the stylus over this window"),
""
);
stylus_placeholder.get_style_context ().remove_class (Gtk.STYLE_CLASS_VIEW);
stylus_placeholder.show_all ();
var stylus_placeholder = new Granite.Placeholder (_("No Stylus Detected")) {
description = _("Move the stylus over this window")
};

tablet_view = new TabletView ();
stylus_view = new StylusView ();

stylus_stack = new Gtk.Stack ();
stylus_stack.add (stylus_view);
stylus_stack.add (stylus_placeholder);
stylus_stack.add_child (stylus_placeholder);
stylus_stack.add_child (stylus_view);

main_box = new Gtk.Box (VERTICAL, 24);
main_box.add (tablet_view);
main_box.add (stylus_stack);
main_box.append (tablet_view);
main_box.append (stylus_stack);

stack = new Gtk.Stack ();
stack.add (main_box);
stack.add (placeholder);

content_area.add (stack);
stack.add_child (main_box);
stack.add_child (placeholder);

show_all ();
child = stack;

device_manager = Backend.DeviceManager.get_default ();
device_manager.device_added.connect (on_device_added);
Expand All @@ -70,9 +60,11 @@ public class Wacom.MainPage : Granite.SimpleSettingsPage {
add_known_device (device);
}

stylus_gesture = new Gtk.GestureStylus (this);
stylus_gesture = new Gtk.GestureStylus ();
stylus_gesture.proximity.connect (on_stylus);

add_controller (stylus_gesture);

update_current_page ();
}

Expand Down Expand Up @@ -117,9 +109,7 @@ public class Wacom.MainPage : Granite.SimpleSettingsPage {
}

private void on_stylus (double object, double p0) {
var event = Gtk.get_current_event ();
var tool = event.get_device_tool ();

var tool = stylus_gesture.get_device_tool ();
if (tool == null) {
critical ("DeviceTool not found");
return;
Expand Down
Loading

0 comments on commit 20156e1

Please sign in to comment.