1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/* Copyright 2016 Software Freedom Conservancy Inc.
*
* This software is licensed under the GNU Lesser General Public License
* (version 2.1 or later). See the COPYING file in this distribution.
*/
public enum AdjustmentRelation {
BELOW,
IN_RANGE,
ABOVE
}
public enum CompassPoint {
NORTH,
SOUTH,
EAST,
WEST
}
public enum Direction {
FORWARD,
BACKWARD;
public Spit.Transitions.Direction to_transition_direction() {
switch (this) {
case FORWARD:
return Spit.Transitions.Direction.FORWARD;
case BACKWARD:
return Spit.Transitions.Direction.BACKWARD;
default:
error("Unknown Direction %s", this.to_string());
}
}
}
public void spin_event_loop() {
while (Gtk.events_pending())
Gtk.main_iteration();
}
public AdjustmentRelation get_adjustment_relation(Gtk.Adjustment adjustment, int value) {
if (value < (int) adjustment.get_value())
return AdjustmentRelation.BELOW;
else if (value > (int) (adjustment.get_value() + adjustment.get_page_size()))
return AdjustmentRelation.ABOVE;
else
return AdjustmentRelation.IN_RANGE;
}
public Gdk.Rectangle get_adjustment_page(Gtk.Adjustment hadj, Gtk.Adjustment vadj) {
Gdk.Rectangle rect = Gdk.Rectangle();
rect.x = (int) hadj.get_value();
rect.y = (int) vadj.get_value();
rect.width = (int) hadj.get_page_size();
rect.height = (int) vadj.get_page_size();
return rect;
}
// Verifies that only the mask bits are set in the modifier field, disregarding mouse and
// key modifiers that are not normally of concern (i.e. Num Lock, Caps Lock, etc.). Mask can be
// one or more bits set, but should only consist of these values:
// * Gdk.ModifierType.SHIFT_MASK
// * Gdk.ModifierType.CONTROL_MASK
// * Gdk.ModifierType.MOD1_MASK (Alt)
// * Gdk.ModifierType.MOD3_MASK
// * Gdk.ModifierType.MOD4_MASK
// * Gdk.ModifierType.MOD5_MASK
// * Gdk.ModifierType.SUPER_MASK
// * Gdk.ModifierType.HYPER_MASK
// * Gdk.ModifierType.META_MASK
//
// (Note: MOD2 seems to be Num Lock in GDK.)
public bool has_only_key_modifier(Gdk.ModifierType field, Gdk.ModifierType mask) {
return (field
& (Gdk.ModifierType.SHIFT_MASK
| Gdk.ModifierType.CONTROL_MASK
| Gdk.ModifierType.MOD1_MASK
| Gdk.ModifierType.MOD3_MASK
| Gdk.ModifierType.MOD4_MASK
| Gdk.ModifierType.MOD5_MASK
| Gdk.ModifierType.SUPER_MASK
| Gdk.ModifierType.HYPER_MASK
| Gdk.ModifierType.META_MASK)) == mask;
}
bool is_pointer_over(Gdk.Window window) {
var seat = window.get_display().get_default_seat();
if (seat == null) {
debug("No seat for display");
return false;
}
int x, y;
seat.get_pointer().get_position(null, out x, out y);
return x >= 0 && y >= 0 && x < window.get_width() && y < window.get_height();
}
|