|
1 | | -// |
2 | | -// Copyright (C) 2020 elementary, Inc. (https://elementary.io) |
3 | | -// |
4 | | -// This program is free software: you can redistribute it and/or modify |
5 | | -// it under the terms of the GNU General Public License as published by |
6 | | -// the Free Software Foundation, either version 3 of the License, or |
7 | | -// (at your option) any later version. |
8 | | -// |
9 | | -// This program is distributed in the hope that it will be useful, |
10 | | -// but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | -// GNU General Public License for more details. |
13 | | -// |
14 | | -// You should have received a copy of the GNU General Public License |
15 | | -// along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | | -// |
17 | | - |
18 | | -namespace Gala { |
19 | | - public class PixelPicker : Clutter.Actor { |
20 | | - public signal void closed (); |
21 | | - |
22 | | - public WindowManager wm { get; construct; } |
23 | | - public bool cancelled { get; private set; } |
24 | | - public Graphene.Point point { get; private set; } |
25 | | - |
26 | | - private ModalProxy? modal_proxy; |
27 | | - |
28 | | - public PixelPicker (WindowManager wm) { |
29 | | - Object (wm: wm); |
30 | | - } |
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | + * SPDX-FileCopyrightText: 2020 elementary, Inc. (https://elementary.io) |
| 4 | + */ |
31 | 5 |
|
32 | | - construct { |
33 | | - point.init (0, 0); |
34 | | - visible = true; |
35 | | - reactive = true; |
| 6 | +public class Gala.PixelPicker : Clutter.Actor { |
| 7 | + public signal void closed (); |
36 | 8 |
|
37 | | - int screen_width, screen_height; |
38 | | - wm.get_display ().get_size (out screen_width, out screen_height); |
39 | | - width = screen_width; |
40 | | - height = screen_height; |
41 | | - } |
| 9 | + public WindowManager wm { get; construct; } |
| 10 | + public bool cancelled { get; private set; } |
| 11 | + public Graphene.Point point { get; private set; } |
| 12 | + |
| 13 | + private ModalProxy? modal_proxy; |
| 14 | + |
| 15 | + public PixelPicker (WindowManager wm) { |
| 16 | + Object (wm: wm); |
| 17 | + } |
| 18 | + |
| 19 | + construct { |
| 20 | + point.init (0, 0); |
| 21 | + visible = true; |
| 22 | + reactive = true; |
| 23 | + |
| 24 | + int screen_width, screen_height; |
| 25 | + wm.get_display ().get_size (out screen_width, out screen_height); |
| 26 | + width = screen_width; |
| 27 | + height = screen_height; |
| 28 | + } |
42 | 29 |
|
43 | 30 | #if HAS_MUTTER45 |
44 | | - public override bool key_press_event (Clutter.Event e) { |
| 31 | + public override bool key_press_event (Clutter.Event e) { |
45 | 32 | #else |
46 | | - public override bool key_press_event (Clutter.KeyEvent e) { |
| 33 | + public override bool key_press_event (Clutter.KeyEvent e) { |
47 | 34 | #endif |
48 | | - if (e.get_key_symbol () == Clutter.Key.Escape) { |
49 | | - close (); |
50 | | - cancelled = true; |
51 | | - closed (); |
52 | | - return true; |
53 | | - } |
54 | | - |
55 | | - return false; |
| 35 | + if (e.get_key_symbol () == Clutter.Key.Escape) { |
| 36 | + cancelled = true; |
| 37 | + close (); |
| 38 | + |
| 39 | + return true; |
56 | 40 | } |
57 | 41 |
|
| 42 | + return false; |
| 43 | + } |
| 44 | + |
58 | 45 | #if HAS_MUTTER45 |
59 | | - public override bool button_release_event (Clutter.Event e) { |
| 46 | + public override bool button_release_event (Clutter.Event e) { |
60 | 47 | #else |
61 | | - public override bool button_release_event (Clutter.ButtonEvent e) { |
| 48 | + public override bool button_release_event (Clutter.ButtonEvent e) { |
62 | 49 | #endif |
63 | | - if (e.get_button () != Clutter.Button.PRIMARY) { |
64 | | - return true; |
65 | | - } |
| 50 | + if (e.get_button () != Clutter.Button.PRIMARY) { |
| 51 | + return true; |
| 52 | + } |
66 | 53 |
|
67 | | - float x, y; |
68 | | - e.get_coords (out x, out y); |
69 | | - point = Graphene.Point () { x = x, y = y }; |
| 54 | + float x, y; |
| 55 | + e.get_coords (out x, out y); |
| 56 | + point = Graphene.Point () { x = x, y = y }; |
70 | 57 |
|
71 | | - close (); |
72 | | - this.hide (); |
| 58 | + this.hide (); |
| 59 | + close (); |
73 | 60 |
|
74 | | - closed (); |
75 | | - return true; |
76 | | - } |
| 61 | + return true; |
| 62 | + } |
77 | 63 |
|
78 | | - public void close () { |
79 | | - wm.get_display ().set_cursor (Meta.Cursor.DEFAULT); |
80 | | - if (modal_proxy != null) { |
81 | | - wm.pop_modal (modal_proxy); |
82 | | - } |
| 64 | + private void close () { |
| 65 | + wm.get_display ().set_cursor (Meta.Cursor.DEFAULT); |
| 66 | + if (modal_proxy != null) { |
| 67 | + wm.pop_modal (modal_proxy); |
83 | 68 | } |
84 | 69 |
|
85 | | - public void start_selection () { |
86 | | - wm.get_display ().set_cursor (Meta.Cursor.CROSSHAIR); |
87 | | - grab_key_focus (); |
| 70 | + closed (); |
| 71 | + } |
88 | 72 |
|
89 | | - modal_proxy = wm.push_modal (this); |
90 | | - } |
| 73 | + public void start_selection () { |
| 74 | + wm.get_display ().set_cursor (Meta.Cursor.CROSSHAIR); |
| 75 | + grab_key_focus (); |
| 76 | + |
| 77 | + modal_proxy = wm.push_modal (this); |
91 | 78 | } |
92 | 79 | } |
0 commit comments