Skip to content
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

Port to GTK4 #157

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install Dependencies
run: |
apt update
apt install -y libhandy-1-dev libcanberra-dev libcanberra-gtk3-dev libgranite-dev libgtk-3-dev meson valac
apt install -y libadwaita-1-dev libcanberra-dev libgranite-dev libgtk-4-dev meson valac
- name: Build
env:
DESTDIR: out
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ a Gtk notification server for Pantheon

You'll need the following dependencies:
* libcanberra
* libcanberra-gtk3
* libgranite-dev (>=5)
* libgtk-3-dev
* libhandy-1-dev (>=0.90.0)
* libgtk-4-dev
* libadwaita-1-dev
* meson
* valac

Expand Down
2 changes: 1 addition & 1 deletion demo/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Application : Gtk.Application {
});

var window = new MainWindow (this);
window.show_all ();
window.present ();
}

public static int main (string[] args) {
Expand Down
20 changes: 12 additions & 8 deletions demo/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,20 @@ public class MainWindow : Gtk.ApplicationWindow {
action_spinbutton = new Gtk.SpinButton.with_range (0, 3, 1);

var send_button = new Gtk.Button.with_label ("Send Notification") {
can_default = true,
// can_default = true,
halign = Gtk.Align.END,
margin_top = 12
};
send_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
send_button.add_css_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);

var grid = new Gtk.Grid () {
valign = Gtk.Align.CENTER,
column_spacing = 12,
row_spacing = 12,
margin = 12
margin_start = 12,
margin_end = 12,
margin_top = 12,
margin_bottom = 12
};
grid.attach (title_entry, 0, 0, 2);
grid.attach (body_entry, 0, 1, 2);
Expand All @@ -96,15 +99,16 @@ public class MainWindow : Gtk.ApplicationWindow {
grid.attach (action_spinbutton, 1, 5);
grid.attach (send_button, 0, 6, 2);

var toast = new Granite.Widgets.Toast ("");
var toast = new Granite.Toast ("");

var overlay = new Gtk.Overlay ();
overlay.add (grid);
var overlay = new Gtk.Overlay () {
child = grid
};
overlay.add_overlay (toast);

add (overlay);
child = overlay;

send_button.has_default = true;
// send_button.has_default = true;
send_button.clicked.connect (send_notification);

var toast_action = new SimpleAction ("toast", VariantType.STRING);
Expand Down
4 changes: 2 additions & 2 deletions demo/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ executable(
'Application.vala',
'MainWindow.vala',
dependencies : [
dependency ('granite'),
dependency ('gtk+-3.0'),
dependency ('granite-7'),
dependency ('gtk4'),
],
install : true
)
Expand Down
10 changes: 6 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ executable(
'src/AbstractBubble.vala',
'src/Application.vala',
'src/Bubble.vala',
'src/CanberraGtk4.vala',
'src/Confirmation.vala',
'src/DBus.vala',
'src/Notification.vala',
'src/Widgets/MaskedImage.vala',
css_gresource,
dependencies: [
dependency ('libcanberra'),
dependency ('libcanberra-gtk3'),
dependency ('gee-0.8'),
dependency ('gio-unix-2.0'),
dependency ('glib-2.0'),
dependency ('gobject-2.0'),
dependency ('granite', version: '>=5.4.0'),
dependency ('gtk+-3.0'),
dependency ('libhandy-1')
dependency ('granite-7'),
dependency ('gtk4'),
dependency ('libadwaita-1')
],
install : true
)
Expand Down
82 changes: 53 additions & 29 deletions src/AbstractBubble.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

public class Notifications.AbstractBubble : Gtk.Window {
public signal void closed (uint32 reason);
public signal void button_release_event ();

protected Gtk.EventControllerMotion bubble_motion_controller;
protected Gtk.Stack content_area;
protected Gtk.Grid draw_area;

private Gtk.Revealer revealer;
private uint timeout_id;
private Hdy.Carousel carousel;
private Adw.Carousel carousel;

construct {
content_area = new Gtk.Stack () {
Expand All @@ -36,57 +38,69 @@ public class Notifications.AbstractBubble : Gtk.Window {

draw_area = new Gtk.Grid () {
hexpand = true,
margin = 16
margin_start = 16,
margin_end = 16,
margin_top = 16,
margin_bottom = 16
};
draw_area.get_style_context ().add_class ("draw-area");
draw_area.add_css_class ("draw-area");
draw_area.attach (content_area, 0, 0);

var close_button = new Gtk.Button.from_icon_name ("window-close-symbolic", Gtk.IconSize.LARGE_TOOLBAR) {
var close_button = new Gtk.Image.from_icon_name ("window-close-symbolic") {
halign = Gtk.Align.START,
valign = Gtk.Align.START
valign = Gtk.Align.START,
pixel_size = 24
};
close_button.get_style_context ().add_class ("close");
close_button.add_css_class ("close");

var close_button_controller = new Gtk.GestureClick ();
close_button.add_controller (close_button_controller);

var close_revealer = new Gtk.Revealer () {
reveal_child = false,
transition_type = Gtk.RevealerTransitionType.CROSSFADE,
halign = Gtk.Align.START,
valign = Gtk.Align.START
valign = Gtk.Align.START,
child = close_button
};
close_revealer.add (close_button);

var overlay = new Gtk.Overlay ();
overlay.add (draw_area);
var overlay = new Gtk.Overlay () {
child = draw_area
};
overlay.add_overlay (close_revealer);

revealer = new Gtk.Revealer () {
reveal_child = true,
transition_duration = 195,
transition_type = Gtk.RevealerTransitionType.CROSSFADE
transition_type = Gtk.RevealerTransitionType.CROSSFADE,
child = overlay
};
revealer.add (overlay);

var label = new Gtk.Grid ();
var label = new Gtk.Grid () {
visible = false
};

carousel = new Hdy.Carousel () {
carousel = new Adw.Carousel () {
allow_mouse_drag = true,
interactive = true,
halign = Gtk.Align.END,
hexpand = true
};
carousel.add (new Gtk.Grid ());
carousel.add (revealer);
carousel.scroll_to (revealer);
// carousel.append (new Gtk.Grid ());
carousel.append (revealer);
carousel.scroll_to (revealer, true);

default_height = 0;
default_width = 332;
resizable = false;
type_hint = Gdk.WindowTypeHint.NOTIFICATION;
// type_hint = Gdk.WindowTypeHint.NOTIFICATION;
get_style_context ().add_class ("notification");
// Prevent stealing focus when an app window is closed
set_accept_focus (false);
can_focus = false;
set_titlebar (label);
add (carousel);
child = carousel;
// Set title to make it recognizable to window manager
title = "io.elementary.notifications";

carousel.page_changed.connect ((index) => {
if (index == 0) {
Expand All @@ -95,24 +109,34 @@ public class Notifications.AbstractBubble : Gtk.Window {
}
});

close_button.button_release_event.connect (() => {
close_button_controller.released.connect (() => {
closed (Notifications.Server.CloseReason.DISMISSED);
dismiss ();
return Gdk.EVENT_STOP;
// return Gdk.EVENT_STOP;
});

enter_notify_event.connect (() => {
var bubble_gesture_controller = new Gtk.GestureClick ();
((Gtk.Widget) this).add_controller (bubble_gesture_controller);

bubble_gesture_controller.released.connect (() => {
button_release_event ();
});

bubble_motion_controller = new Gtk.EventControllerMotion ();
revealer.add_controller (bubble_motion_controller);

bubble_motion_controller.enter.connect (() => {
close_revealer.reveal_child = true;
stop_timeout ();
return Gdk.EVENT_PROPAGATE;
// return Gdk.EVENT_PROPAGATE;
});

leave_notify_event.connect ((event) => {
if (event.detail == Gdk.NotifyType.INFERIOR) {
return Gdk.EVENT_STOP;
}
bubble_motion_controller.leave.connect ((event) => {
// if (event.detail == Gdk.NotifyType.INFERIOR) {
// return Gdk.EVENT_STOP;
// }
close_revealer.reveal_child = false;
return Gdk.EVENT_PROPAGATE;
// return Gdk.EVENT_PROPAGATE;
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public class Notifications.Application : Gtk.Application {

var css_provider = new Gtk.CssProvider ();
css_provider.load_from_resource (resource_base_path + "/application.css");
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
Gtk.StyleContext.add_provider_for_display (Gdk.Display.get_default (), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

unowned var context = CanberraGtk.context_get ();
unowned var context = CanberraGtk4.context_get ();
context.change_props (
Canberra.PROP_APPLICATION_NAME, "Notifications",
Canberra.PROP_APPLICATION_ID, application_id,
Expand Down
35 changes: 19 additions & 16 deletions src/Bubble.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public class Notifications.Bubble : AbstractBubble {
construct {
var contents = new Contents (notification);

content_area.add (contents);
content_area.add_child (contents);

switch (notification.priority) {
case GLib.NotificationPriority.HIGH:
case GLib.NotificationPriority.URGENT:
content_area.get_style_context ().add_class ("urgent");
content_area.add_css_class ("urgent");
break;
default:
start_timeout (4000);
Expand Down Expand Up @@ -74,13 +74,13 @@ public class Notifications.Bubble : AbstractBubble {
}
}

return Gdk.EVENT_STOP;
// return Gdk.EVENT_STOP;
});

leave_notify_event.connect (() => {
if (notification.priority == GLib.NotificationPriority.HIGH || notification.priority == GLib.NotificationPriority.URGENT) {
return Gdk.EVENT_PROPAGATE;
}
bubble_motion_controller.leave.connect (() => {
// if (notification.priority == GLib.NotificationPriority.HIGH || notification.priority == GLib.NotificationPriority.URGENT) {
// return Gdk.EVENT_PROPAGATE;
// }
start_timeout (4000);
});
}
Expand All @@ -89,14 +89,14 @@ public class Notifications.Bubble : AbstractBubble {
start_timeout (4000);

var new_contents = new Contents (new_notification);
new_contents.show_all ();
new_contents.show ();

new_contents.action_invoked.connect ((action_key) => {
action_invoked (action_key);
dismiss ();
});

content_area.add (new_contents);
content_area.add_child (new_contents);
content_area.visible_child = new_contents;
}

Expand All @@ -121,14 +121,14 @@ public class Notifications.Bubble : AbstractBubble {
app_image.pixel_size = 24;
app_image.halign = app_image.valign = Gtk.Align.END;

image_overlay.add (notification.image);
image_overlay.child = notification.image;
image_overlay.add_overlay (app_image);
} else {
app_image.pixel_size = 48;
image_overlay.add (app_image);
image_overlay.child = app_image;

if (notification.badge_icon != null) {
var badge_image = new Gtk.Image.from_gicon (notification.badge_icon, Gtk.IconSize.LARGE_TOOLBAR) {
var badge_image = new Gtk.Image.from_gicon (notification.badge_icon) {
halign = Gtk.Align.END,
valign = Gtk.Align.END,
pixel_size = 24
Expand All @@ -144,7 +144,7 @@ public class Notifications.Bubble : AbstractBubble {
width_chars = 33,
xalign = 0
};
title_label.get_style_context ().add_class ("title");
title_label.add_css_class ("title");

var body_label = new Gtk.Label (notification.body) {
ellipsize = Pango.EllipsizeMode.END,
Expand Down Expand Up @@ -179,20 +179,23 @@ public class Notifications.Bubble : AbstractBubble {
halign = Gtk.Align.END,
homogeneous = true
};
action_area.get_style_context ().add_class ("buttonbox");
action_area.add_css_class ("buttonbox");

bool action_area_packed = false;

for (int i = 0; i < notification.actions.length; i += 2) {
if (notification.actions[i] != "default") {
var button = new Gtk.Button.with_label (notification.actions[i + 1]);
var button = new Gtk.Button.with_label (notification.actions[i + 1]) {
width_request = 85,
height_request = 27
};
var action = notification.actions[i].dup ();

button.clicked.connect (() => {
action_invoked (action);
});

action_area.pack_end (button);
action_area.prepend (button);

if (!action_area_packed) {
attach (action_area, 0, 2, 2);
Expand Down
Loading