godot_status_item.mm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #include "godot_status_item.h"
  31. #include "display_server_macos.h"
  32. @implementation GodotStatusItemDelegate
  33. - (id)init {
  34. self = [super init];
  35. return self;
  36. }
  37. - (IBAction)click:(id)sender {
  38. NSEvent *current_event = [NSApp currentEvent];
  39. MouseButton index = MouseButton::LEFT;
  40. if (current_event) {
  41. if (current_event.type == NSEventTypeLeftMouseDown) {
  42. index = MouseButton::LEFT;
  43. } else if (current_event.type == NSEventTypeRightMouseDown) {
  44. index = MouseButton::RIGHT;
  45. } else if (current_event.type == NSEventTypeOtherMouseDown) {
  46. if ((int)[current_event buttonNumber] == 2) {
  47. index = MouseButton::MIDDLE;
  48. } else if ((int)[current_event buttonNumber] == 3) {
  49. index = MouseButton::MB_XBUTTON1;
  50. } else if ((int)[current_event buttonNumber] == 4) {
  51. index = MouseButton::MB_XBUTTON2;
  52. }
  53. }
  54. }
  55. DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
  56. if (!ds) {
  57. return;
  58. }
  59. if (cb.is_valid()) {
  60. Variant v_button = index;
  61. Variant v_pos = ds->mouse_get_position();
  62. const Variant *v_args[2] = { &v_button, &v_pos };
  63. Variant ret;
  64. Callable::CallError ce;
  65. cb.callp((const Variant **)&v_args, 2, ret, ce);
  66. if (ce.error != Callable::CallError::CALL_OK) {
  67. ERR_PRINT(vformat("Failed to execute status indicator callback: %s.", Variant::get_callable_error_text(cb, v_args, 2, ce)));
  68. }
  69. }
  70. }
  71. - (void)setCallback:(const Callable &)callback {
  72. cb = callback;
  73. }
  74. @end