Atlas - SDL_qnxmouse.c

Home / ext / SDL / src / video / qnx Lines: 1 | Size: 5335 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 2026 BlackBerry Limited 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21 22#include "SDL_internal.h" 23#include "../SDL_sysvideo.h" 24#include "SDL_qnx.h" 25#include "../../events/SDL_mouse_c.h" 26 27#include <errno.h> 28 29 30static int SDLToScreenCursorShape(SDL_SystemCursor id) 31{ 32 // This is reserved by screen, but still not used for anything. 33 int shape = -1; 34 35 switch(id) 36 { 37 case SDL_SYSTEM_CURSOR_DEFAULT: 38 case SDL_SYSTEM_CURSOR_NOT_ALLOWED: 39 shape = SCREEN_CURSOR_SHAPE_ARROW; 40 break; 41 case SDL_SYSTEM_CURSOR_TEXT: 42 shape = SCREEN_CURSOR_SHAPE_IBEAM; 43 break; 44 case SDL_SYSTEM_CURSOR_WAIT: 45 shape = SCREEN_CURSOR_SHAPE_WAIT; 46 break; 47 case SDL_SYSTEM_CURSOR_CROSSHAIR: 48 shape = SCREEN_CURSOR_SHAPE_CROSS; 49 break; 50 case SDL_SYSTEM_CURSOR_NWSE_RESIZE: 51 case SDL_SYSTEM_CURSOR_NESW_RESIZE: 52 case SDL_SYSTEM_CURSOR_EW_RESIZE: 53 case SDL_SYSTEM_CURSOR_NS_RESIZE: 54 case SDL_SYSTEM_CURSOR_MOVE: 55 shape = SCREEN_CURSOR_SHAPE_MOVE; 56 break; 57 case SDL_SYSTEM_CURSOR_POINTER: 58 shape = SCREEN_CURSOR_SHAPE_HAND; 59 break; 60 default: 61 break; 62 } 63 return shape; 64} 65 66static SDL_Cursor *genericCreateCursor(int shape) 67{ 68 SDL_Cursor *cursor; 69 SDL_CursorData *impl; 70 screen_session_t session; 71 screen_context_t *context = getContext(); 72 73 cursor = SDL_calloc(1, sizeof(SDL_Cursor)); 74 if (cursor) { 75 impl = SDL_calloc(1, sizeof(SDL_CursorData));; 76 if (impl == NULL) { 77 SDL_free(cursor); 78 SDL_OutOfMemory(); 79 } 80 impl->realized_shape = shape; 81 82 screen_create_session_type(&session, *context, SCREEN_EVENT_POINTER); 83 screen_set_session_property_iv(session, SCREEN_PROPERTY_CURSOR, &shape); 84 85 impl->session = session; 86 impl->is_visible = true; 87 cursor->internal = (void*)impl; 88 } else { 89 SDL_OutOfMemory(); 90 } 91 92 return cursor; 93} 94 95static SDL_Cursor *createCursor(SDL_Surface * surface, int hot_x, int hot_y) 96{ 97 return genericCreateCursor(SCREEN_CURSOR_SHAPE_ARROW); 98} 99 100static SDL_Cursor *createSystemCursor(SDL_SystemCursor id) 101{ 102 int shape = SDLToScreenCursorShape(id); 103 if (shape < 0) { 104 SDL_assert(0); 105 return NULL; 106 } 107 108 return genericCreateCursor(shape); 109} 110 111static bool showCursor(SDL_Cursor * cursor) 112{ 113 SDL_CursorData *impl; 114 screen_session_t session; 115 int shape; 116 117 // SDL does not provide information about previous visibility to its 118 // drivers. We need to track that ourselves. 119 if (cursor) { 120 impl = (SDL_CursorData*)cursor->internal; 121 SDL_assert(impl != NULL); 122 if (impl->is_visible) { 123 return true; 124 } 125 session = impl->session; 126 shape = impl->realized_shape; 127 impl->is_visible = true; 128 } else { 129 cursor = SDL_GetCursor(); 130 if (cursor == NULL) { 131 return false; 132 } 133 impl = (SDL_CursorData*)cursor->internal; 134 SDL_assert(impl != NULL); 135 if (!impl->is_visible) { 136 return 0; 137 } 138 session = impl->session; 139 shape = SCREEN_CURSOR_SHAPE_NONE; 140 impl->is_visible = false; 141 } 142 143 if (screen_set_session_property_iv(session, SCREEN_PROPERTY_CURSOR, &shape) < 0) { 144 return false; 145 } 146 147 return true; 148} 149 150static void freeCursor(SDL_Cursor * cursor) 151{ 152 SDL_CursorData *impl = (SDL_CursorData*)cursor->internal; 153 if (impl != NULL) { 154 screen_destroy_session(impl->session); 155 SDL_free(impl); 156 } 157 SDL_free(cursor); 158} 159 160static bool setRelativeMouseMode(bool enabled) 161{ 162 // We're tracking rel-position explicitly, but this is still needed so 163 // SDL_SetRelativeMouseMode() & friends aren't a no-op. 164 // 165 // TODO: It may be possible to achieve this using SCREEN_PROPERTY_DISPLACEMENT instead. 166 return true; 167} 168 169void initMouse(SDL_VideoDevice *_this) 170{ 171 SDL_Mouse *mouse = SDL_GetMouse(); 172 SDL_MouseData *mouse_data; 173 174 mouse_data = (SDL_MouseData *)SDL_calloc(1, sizeof(SDL_MouseData)); 175 if (mouse_data == NULL) { 176 return; 177 } 178 SDL_zerop(mouse_data); 179 mouse->internal = mouse_data; 180 181 mouse->CreateCursor = createCursor; 182 mouse->CreateSystemCursor = createSystemCursor; 183 mouse->ShowCursor = showCursor; 184 mouse->FreeCursor = freeCursor; 185 186 mouse->SetRelativeMouseMode = setRelativeMouseMode; 187 188 SDL_SetDefaultCursor(createCursor(NULL, 0, 0)); 189} 190
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.