From 405ae5e8a8cad45b680faeeabcb2a14cf315ff1c Mon Sep 17 00:00:00 2001 From: Melody Madeline Lyons Date: Thu, 15 Aug 2024 15:52:35 -0700 Subject: [PATCH] Add some more window manip methods --- binding/modshot-window-binding.cpp | 28 ++++++++++++++++++++ binding/osfm-screen-binding.cpp | 41 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/binding/modshot-window-binding.cpp b/binding/modshot-window-binding.cpp index f52ed7c4d..acb58fe43 100644 --- a/binding/modshot-window-binding.cpp +++ b/binding/modshot-window-binding.cpp @@ -1,3 +1,4 @@ +#include "SDL3/SDL_video.h" #include "oneshot.h" #include "sharedstate.h" #include "binding-util.h" @@ -72,6 +73,30 @@ RB_METHOD(SetWindowOpacity) { return Qnil; } +RB_METHOD(SetAlwaysOnTop) { + bool top; + rb_get_args(argc, argv, "b", &top); + SDL_SetWindowAlwaysOnTop(shState->rtData().window, top); + return Qnil; +} + +RB_METHOD(FlashWindow) { + int state; + rb_get_args(argc, argv, "i", &state); + + if (state < SDL_FLASH_CANCEL || state > SDL_FLASH_UNTIL_FOCUSED) + rb_raise(rb_eArgError, "Invalid flash state"); + + SDL_FlashWindow(shState->rtData().window, (SDL_FlashOperation) state); + return Qnil; +} + +RB_METHOD(WindowRaise) { + RB_UNUSED_PARAM; + SDL_RaiseWindow(shState->rtData().window); + return Qnil; +} + void modshotwindowBindingInit() { VALUE module = rb_define_module("ModWindow"); @@ -80,5 +105,8 @@ void modshotwindowBindingInit() _rb_define_module_function(module, "SetTitle", SetTitle); _rb_define_module_function(module, "SetIcon", SetIcon); _rb_define_module_function(module, "setWindowOpacity", SetWindowOpacity); + _rb_define_module_function(module, "setAlwaysOnTop", SetAlwaysOnTop); + _rb_define_module_function(module, "flashWindow", FlashWindow); + _rb_define_module_function(module, "raiseWindow", WindowRaise); //_rb_define_module_function(module, "setWindowChromaKey", SetTransparentColor); } \ No newline at end of file diff --git a/binding/osfm-screen-binding.cpp b/binding/osfm-screen-binding.cpp index 11b911d03..5e702d109 100644 --- a/binding/osfm-screen-binding.cpp +++ b/binding/osfm-screen-binding.cpp @@ -462,6 +462,44 @@ RB_METHOD(monitorWindowHide) { return Qnil; } +RB_METHOD(monitorSetAlwaysOnTop) { + MonitorWindow* window = getPrivateData(self); + + GUARD_DISPOSED(window); + + bool top; + rb_get_args(argc, argv, "b", &top); + + SDL_SetWindowAlwaysOnTop(window->window, top); + + return Qnil; +} + +RB_METHOD(monitorFlashWindow) { + MonitorWindow* window = getPrivateData(self); + + GUARD_DISPOSED(window); + + int state; + rb_get_args(argc, argv, "i", &state); + + if (state < SDL_FLASH_CANCEL || state > SDL_FLASH_UNTIL_FOCUSED) + rb_raise(rb_eArgError, "Invalid flash state"); + + SDL_FlashWindow(window->window, (SDL_FlashOperation) state); + return Qnil; +} + +RB_METHOD(monitorWindowRaise) { + MonitorWindow* window = getPrivateData(self); + + GUARD_DISPOSED(window); + + SDL_RaiseWindow(window->window); + + return Qnil; +} + void osfmBindingInit() { VALUE klass = rb_define_class("MonitorWindow", rb_cObject); @@ -475,6 +513,9 @@ void osfmBindingInit() { _rb_define_method(klass, "position", monitorWindowPos); _rb_define_method(klass, "show", monitorWindowShow); _rb_define_method(klass, "hide", monitorWindowHide); + _rb_define_method(klass, "set_always_on_top", monitorSetAlwaysOnTop); + _rb_define_method(klass, "flash", monitorFlashWindow); + _rb_define_method(klass, "raise", monitorWindowRaise); rb_define_const(klass, "UNDEFINED_POS", INT2NUM(SDL_WINDOWPOS_UNDEFINED)); rb_define_const(klass, "CENTERED_POS", INT2NUM(SDL_WINDOWPOS_CENTERED));