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

Move drag gesture to overlay; simplify #376

Merged
merged 20 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 17 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
71 changes: 17 additions & 54 deletions src/Widgets/DisplayWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,16 @@ public struct Display.Resolution {

public class Display.DisplayWidget : Gtk.EventBox {
public signal void set_as_primary ();
public signal void move_display (double diff_x, double diff_y);
public signal void end_grab (int delta_x, int delta_y);
public signal void check_position ();
public signal void configuration_changed ();
public signal void active_changed ();

public Display.VirtualMonitor virtual_monitor { get; construct; }
public string display_name { get {return virtual_monitor.get_display_name (); }}

public double window_ratio { get; private set; default = 1.0; }
public int delta_x { get; set; default = 0; }
public int delta_y { get; set; default = 0; }
public bool only_display { get; set; default = false; }

private double start_x = 0;
private double start_y = 0;
private bool holding = false;

public DisplayWindow display_window { get; private set; }
public bool connected { get; set; }
public Gtk.Button primary_image { get; private set; }
public Gtk.MenuButton toggle_settings { get; private set; }

Expand All @@ -63,9 +55,6 @@ public class Display.DisplayWidget : Gtk.EventBox {
private int real_width = 0;
private int real_height = 0;

private Gtk.EventControllerMotion motion_event_controller;
private Gtk.GestureMultiPress click_gesture;

private enum ResolutionColumns {
NAME,
WIDTH,
Expand All @@ -90,10 +79,6 @@ public class Display.DisplayWidget : Gtk.EventBox {
}

construct {
events |= Gdk.EventMask.BUTTON_PRESS_MASK;
events |= Gdk.EventMask.BUTTON_RELEASE_MASK;
events |= Gdk.EventMask.POINTER_MOTION_MASK;

display_window = new DisplayWindow (virtual_monitor) {
attached_to = this
};
Expand Down Expand Up @@ -328,7 +313,7 @@ public class Display.DisplayWidget : Gtk.EventBox {
return;
}

set_geometry (virtual_monitor.x, virtual_monitor.y, active_width, active_height);
set_virtual_monitor_geometry (virtual_monitor.x, virtual_monitor.y, active_width, active_height);
var new_mode = virtual_monitor.get_mode_for_resolution (active_width, active_height);
if (new_mode == null) {
return;
Expand Down Expand Up @@ -419,12 +404,6 @@ public class Display.DisplayWidget : Gtk.EventBox {
configuration_changed ();
check_position ();

click_gesture = new Gtk.GestureMultiPress (this);
click_gesture.pressed.connect (gesture_press_event);
click_gesture.released.connect (gesture_release_event);

motion_event_controller = new Gtk.EventControllerMotion (this);
motion_event_controller.motion.connect (motion_event);
}

private void populate_refresh_rates () {
Expand Down Expand Up @@ -532,34 +511,6 @@ public class Display.DisplayWidget : Gtk.EventBox {
});
}

private void gesture_press_event (int n_press, double x, double y) {
if (only_display) {
return;
}

start_x = x;
start_y = y;
holding = true;
}

private void gesture_release_event (int n_press, double x, double y) {
holding = false;
if ((delta_x == 0 && delta_y == 0) || only_display) {
return;
}

var old_delta_x = delta_x;
var old_delta_y = delta_y;
delta_x = 0;
delta_y = 0;
end_grab (old_delta_x, old_delta_y);
}

private void motion_event (double event_x, double event_y) {
if (holding && !only_display) {
move_display (event_x - start_x, event_y - start_y);
}
}

public void set_primary (bool is_primary) {
if (is_primary) {
Expand All @@ -583,18 +534,30 @@ public class Display.DisplayWidget : Gtk.EventBox {
natural_height = minimum_height;
}

public void get_geometry (out int x, out int y, out int width, out int height) {
public void get_virtual_monitor_geometry (out int x, out int y, out int width, out int height) {
x = virtual_monitor.x;
y = virtual_monitor.y;
width = real_width;
height = real_height;
}

public void set_geometry (int x, int y, int width, int height) {
public void set_virtual_monitor_geometry (int x, int y, int width, int height) {
virtual_monitor.x = x;
virtual_monitor.y = y;
real_width = width;
real_height = height;

queue_resize_no_redraw ();
}

public void move_x (int dx) {
virtual_monitor.x += dx;
queue_resize_no_redraw ();
}

public void move_y (int dy) {
virtual_monitor.y += dy;
queue_resize_no_redraw ();
}

public bool equals (DisplayWidget sibling) {
Expand Down
Loading