Skip to content

Wayland events #699

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

Merged
merged 3 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 26 additions & 8 deletions src/classes/window/controllable.vala
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ namespace pdfpc.Window {
true);
});

if (this.interactive) {
this.register_presenter_handlers();
}

// Soft cursor drawing events
this.pointer_drawing_surface.draw.connect(this.draw_pointer);
this.pen_drawing_surface.draw.connect(this.draw_pen);
Expand All @@ -157,6 +153,13 @@ namespace pdfpc.Window {
this.destroy.connect((source) => controller.quit());
}

protected void add_top_container(Gtk.Widget top) {
this.add(top);
if (this.interactive) {
this.register_presenter_handlers(top);
}
}

public void enable_pointer(bool onoff) {
if (onoff) {
this.pointer_drawing_surface.show();
Expand All @@ -173,7 +176,7 @@ namespace pdfpc.Window {
}
}

protected void register_presenter_handlers() {
protected void register_presenter_handlers(Gtk.Widget top) {
// Main view events
var view = this.main_view;
view.add_events(Gdk.EventMask.ENTER_NOTIFY_MASK |
Expand All @@ -187,8 +190,14 @@ namespace pdfpc.Window {

// General controlling events acting on the whole window
this.key_press_event.connect(this.w_on_key_press);
this.button_press_event.connect(this.w_on_button_press);

this.add_events(Gdk.EventMask.SCROLL_MASK);
this.scroll_event.connect(this.w_on_scroll);

// Wayland treats the window decorations as part of the window.
// Thus, we assign the mouse handler to the top widget instead,
// so the WM actions like resize & drag continue working.
top.button_press_event.connect(this.w_on_button_press);
}

/**
Expand Down Expand Up @@ -330,8 +339,8 @@ namespace pdfpc.Window {
* Handle mouse scrolling
*/
protected bool w_on_scroll(Gdk.EventScroll scroll) {
bool up = false;
bool down = false;
bool up = false, down = false;

switch (scroll.direction) {
case Gdk.ScrollDirection.UP:
case Gdk.ScrollDirection.LEFT:
Expand All @@ -341,6 +350,15 @@ namespace pdfpc.Window {
case Gdk.ScrollDirection.RIGHT:
down = true;
break;
case Gdk.ScrollDirection.SMOOTH:
double dx, dy;
scroll.get_scroll_deltas(out dx, out dy);
if (dx > 0 || dy > 0) {
down = true;
} else if (dx < 0 || dy < 0) {
up = true;
}
break;
default:
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/classes/window/presentation.vala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ namespace pdfpc.Window {
var frame = new Gtk.AspectFrame(null, 0.5f, 0.5f,
(float) ratio, false);
frame.add(overlay_layout);
this.add(frame);

this.add_top_container(frame);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/classes/window/presenter.vala
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ namespace pdfpc.Window {
full_overlay.add_overlay(this.toolbox);
full_overlay.set_overlay_pass_through(this.toolbox, true);

this.add(full_overlay);
this.add_top_container(full_overlay);
}

public void session_saved() {
Expand Down