Skip to content

Commit 812c188

Browse files
Fix window drag (#558)
Co-authored-by: lenemter <lenemter@gmail.com>
1 parent a736c1d commit 812c188

File tree

7 files changed

+43
-75
lines changed

7 files changed

+43
-75
lines changed

src/PanelWindow.vala

+3-12
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public class Wingpanel.PanelWindow : Gtk.Window {
2222

2323
private Widgets.Panel panel;
2424
private Gtk.EventControllerKey key_controller; // For keeping in memory
25-
private Gtk.GestureMultiPress gesture_controller; // For keeping in memory
2625
private Gtk.Revealer revealer;
2726
private int monitor_width;
2827
private int monitor_height;
@@ -80,24 +79,14 @@ public class Wingpanel.PanelWindow : Gtk.Window {
8079
key_controller = new Gtk.EventControllerKey (this);
8180
key_controller.key_pressed.connect (on_key_pressed);
8281

83-
gesture_controller = new Gtk.GestureMultiPress (this) {
84-
propagation_phase = CAPTURE
85-
};
86-
87-
gesture_controller.pressed.connect (() => {
88-
if (desktop_panel != null) {
89-
desktop_panel.focus ();
90-
}
91-
});
92-
9382
panel.size_allocate.connect (update_panel_dimensions);
9483
}
9584

9685
private void on_realize () {
9786
update_panel_dimensions ();
9887
Services.BackgroundManager.initialize (panel_height);
9988

100-
if (Utils.is_wayland ()) {
89+
if (Gdk.Display.get_default () is Gdk.Wayland.Display) {
10190
// We have to wrap in Idle otherwise the Meta.Window of the WaylandSurface in Gala is still null
10291
Idle.add_once (init_wl);
10392
} else {
@@ -141,6 +130,8 @@ public class Wingpanel.PanelWindow : Gtk.Window {
141130

142131
this.expanded = true;
143132
this.set_size_request (monitor_width, monitor_height);
133+
134+
desktop_panel.focus ();
144135
} else if (!expand) {
145136
Services.BackgroundManager.get_default ().restore_window ();
146137

src/Services/BackgroundManager.vala

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace Wingpanel.Services {
3333
public abstract void initialize (int panel_height) throws GLib.Error;
3434
public abstract void remember_focused_window () throws GLib.Error;
3535
public abstract void restore_focused_window () throws GLib.Error;
36-
public abstract bool begin_grab_focused_window (int x, int y, int button, uint time, uint state) throws GLib.Error;
36+
public abstract bool begin_grab_focused_window (int x, int y) throws GLib.Error;
3737
}
3838

3939
public class BackgroundManager : Object {
@@ -106,9 +106,9 @@ namespace Wingpanel.Services {
106106
}
107107
}
108108

109-
public bool begin_grab_focused_window (int x, int y, int button, uint time, uint state) {
109+
public bool begin_grab_focused_window (int x, int y) {
110110
try {
111-
return bus.begin_grab_focused_window (x, y, button, time, state);
111+
return bus.begin_grab_focused_window (x, y);
112112
} catch (Error e) {
113113
warning ("Grabbing focused window failed: %s", e.message);
114114
}

src/Utils.vala

-24
This file was deleted.

src/Widgets/Panel.vala

+7-24
Original file line numberDiff line numberDiff line change
@@ -71,42 +71,25 @@ public class Wingpanel.Widgets.Panel : Gtk.EventBox {
7171
style_context = get_style_context ();
7272

7373
Services.BackgroundManager.get_default ().background_state_changed.connect (update_background);
74-
}
75-
76-
public override bool button_press_event (Gdk.EventButton event) {
77-
if (Utils.is_wayland ()) {
78-
return Gdk.EVENT_PROPAGATE;
79-
}
8074

81-
if (event.button != Gdk.BUTTON_PRIMARY) {
75+
button_press_event.connect ((event) => {
76+
begin_drag (event.x_root, event.y_root);
8277
return Gdk.EVENT_PROPAGATE;
83-
}
78+
});
79+
}
8480

81+
private void begin_drag (double x, double y) {
8582
var window = get_window ();
8683
if (window == null) {
87-
return Gdk.EVENT_PROPAGATE;
88-
}
89-
90-
// Grabbing with touchscreen on X does not work unfortunately
91-
if (event.device.get_source () == Gdk.InputSource.TOUCHSCREEN) {
92-
return Gdk.EVENT_PROPAGATE;
84+
return;
9385
}
9486

95-
uint32 time = event.time;
96-
9787
window.get_display ().get_default_seat ().ungrab ();
9888

99-
Gdk.ModifierType state;
100-
event.get_state (out state);
101-
10289
popover_manager.close ();
10390

104-
var scale_factor = this.get_scale_factor ();
105-
var x = (int)event.x_root * scale_factor;
106-
var y = (int)event.y_root * scale_factor;
107-
10891
var background_manager = Services.BackgroundManager.get_default ();
109-
return background_manager.begin_grab_focused_window (x, y, (int)event.button, time, state);
92+
background_manager.begin_grab_focused_window ((int) x, (int) y);
11093
}
11194

11295
public void cycle (bool forward) {

src/meson.build

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ wingpanel_files = files(
22
'PanelWindow.vala',
33
'SessionManager.vala',
44
'Application.vala',
5-
'Utils.vala',
65
'Services/BackgroundManager.vala',
76
'Services/IndicatorSorter.vala',
87
'Services/PopoverManager.vala',

wingpanel-interface/DBusServer.vala

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public class WingpanelInterface.DBusServer : Object {
3333
focus_manager = new FocusManager ();
3434
}
3535

36-
public bool begin_grab_focused_window (int x, int y, int button, uint time, uint state) throws GLib.Error {
37-
return focus_manager.begin_grab_focused_window (x, y, button, time, state);
36+
public bool begin_grab_focused_window (int x, int y) throws GLib.Error {
37+
return focus_manager.begin_grab_focused_window (x, y);
3838
}
3939

4040
public void remember_focused_window () throws GLib.Error {

wingpanel-interface/FocusManager.vala

+28-9
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public class WingpanelInterface.FocusManager : Object {
8989
}
9090
}
9191

92-
public bool begin_grab_focused_window (int x, int y, int button, uint time, uint state) {
92+
public bool begin_grab_focused_window (int x, int y) {
9393
unowned var display = Main.display;
9494
unowned var window = display.get_focus_window ();
9595
if (window == null || !get_can_grab_window (window, x, y)) {
@@ -114,15 +114,34 @@ public class WingpanelInterface.FocusManager : Object {
114114
}
115115

116116
if (window != null) {
117+
unowned var wm = Main.wm;
118+
unowned var stage = wm.stage;
117119

118-
#if HAS_MUTTER46
119-
Graphene.Point pos_hint = {x, y};
120-
window.begin_grab_op (Meta.GrabOp.MOVING, null, null, time, pos_hint);
121-
#elif HAS_MUTTER44
122-
window.begin_grab_op (Meta.GrabOp.MOVING, null, null, time);
123-
#else
124-
display.begin_grab_op (window, Meta.GrabOp.MOVING, false, true, button, state, time, x, y);
125-
#endif
120+
var proxy = wm.push_modal (stage);
121+
122+
ulong handler = 0;
123+
handler = stage.captured_event.connect ((event) => {
124+
if (event.get_type () == LEAVE) {
125+
/* We get leave emitted when beginning a grab op, so we have
126+
to filter it in order to avoid disconnecting and popping twice */
127+
return Clutter.EVENT_PROPAGATE;
128+
}
129+
130+
if (event.get_type () == MOTION || event.get_type () == TOUCH_UPDATE) {
131+
window.begin_grab_op (
132+
Meta.GrabOp.MOVING,
133+
event.get_device (),
134+
event.get_event_sequence (),
135+
event.get_time (),
136+
{ x, y }
137+
);
138+
}
139+
140+
wm.pop_modal (proxy);
141+
stage.disconnect (handler);
142+
143+
return Clutter.EVENT_PROPAGATE;
144+
});
126145
return true;
127146
}
128147

0 commit comments

Comments
 (0)