Debian Codegraph @

platform/macos/godot_status_item.mm

raw
1 /**************************************************************************/
2 /* godot_status_item.mm */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #import "godot_status_item.h"
32
33 #import "display_server_macos.h"
34
35 @implementation GodotStatusItemDelegate
36
37 - (id)init {
38 self = [super init];
39 return self;
40 }
41
42 - (IBAction)click:(id)sender {
43 NSEvent *current_event = [NSApp currentEvent];
44 MouseButton index = MouseButton::LEFT;
45 if (current_event) {
46 if (current_event.type == NSEventTypeLeftMouseDown) {
47 index = MouseButton::LEFT;
48 } else if (current_event.type == NSEventTypeRightMouseDown) {
49 index = MouseButton::RIGHT;
50 } else if (current_event.type == NSEventTypeOtherMouseDown) {
51 if ((int)[current_event buttonNumber] == 2) {
52 index = MouseButton::MIDDLE;
53 } else if ((int)[current_event buttonNumber] == 3) {
54 index = MouseButton::MB_XBUTTON1;
55 } else if ((int)[current_event buttonNumber] == 4) {
56 index = MouseButton::MB_XBUTTON2;
57 }
58 }
59 }
60
61 DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
62 if (!ds) {
63 return;
64 }
65
66 if (cb.is_valid()) {
67 Variant v_button = index;
68 Variant v_pos = ds->mouse_get_position();
69 const Variant *v_args[2] = { &v_button, &v_pos };
70 Variant ret;
71 Callable::CallError ce;
72 cb.callp((const Variant **)&v_args, 2, ret, ce);
73 if (ce.error != Callable::CallError::CALL_OK) {
74 ERR_PRINT(vformat("Failed to execute status indicator callback: %s.", Variant::get_callable_error_text(cb, v_args, 2, ce)));
75 }
76 }
77 }
78
79 - (void)setCallback:(const Callable &)callback {
80 cb = callback;
81 }
82
83 @end