2
0
mirror of https://github.com/arnavbhatt288/sdl-2.30.3-kolibri.git synced 2025-01-21 11:08:14 +01:00

add other window functions + other changes

Signed-off-by: Arnav Bhatt <arnav@ghativega.in>
This commit is contained in:
Arnav Bhatt 2024-07-06 17:58:13 +05:30
parent 6ffbce2cd7
commit c164d8f0a5
No known key found for this signature in database
GPG Key ID: 2F49C4D36103865D
10 changed files with 180 additions and 105 deletions

View File

@ -28,10 +28,10 @@
#ifndef SDL_syswm_h_ #ifndef SDL_syswm_h_
#define SDL_syswm_h_ #define SDL_syswm_h_
#include "SDL_stdinc.h"
#include "SDL_error.h" #include "SDL_error.h"
#include "SDL_video.h" #include "SDL_stdinc.h"
#include "SDL_version.h" #include "SDL_version.h"
#include "SDL_video.h"
/** /**
* \brief SDL_syswm.h * \brief SDL_syswm.h
@ -66,8 +66,8 @@ struct SDL_SysWMinfo;
#define Cursor X11Cursor #define Cursor X11Cursor
#endif #endif
#include <X11/Xlib.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/Xlib.h>
#if defined(__APPLE__) && defined(__MACH__) #if defined(__APPLE__) && defined(__MACH__)
/* matches the re-define above */ /* matches the re-define above */
@ -121,7 +121,6 @@ typedef void *EGLSurface;
struct gbm_device; struct gbm_device;
#endif #endif
#include "begin_code.h" #include "begin_code.h"
/* Set up for C function definitions, even when using C++ */ /* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus #ifdef __cplusplus
@ -148,7 +147,8 @@ typedef enum
SDL_SYSWM_OS2, SDL_SYSWM_OS2,
SDL_SYSWM_HAIKU, SDL_SYSWM_HAIKU,
SDL_SYSWM_KMSDRM, SDL_SYSWM_KMSDRM,
SDL_SYSWM_RISCOS SDL_SYSWM_RISCOS,
SDL_SYSWM_KOLIBRI
} SDL_SYSWM_TYPE; } SDL_SYSWM_TYPE;
/** /**
@ -161,7 +161,8 @@ struct SDL_SysWMmsg
union union
{ {
#if defined(SDL_VIDEO_DRIVER_WINDOWS) #if defined(SDL_VIDEO_DRIVER_WINDOWS)
struct { struct
{
HWND hwnd; /**< The window for the message */ HWND hwnd; /**< The window for the message */
UINT msg; /**< The type of message */ UINT msg; /**< The type of message */
WPARAM wParam; /**< WORD message parameter */ WPARAM wParam; /**< WORD message parameter */
@ -169,12 +170,14 @@ struct SDL_SysWMmsg
} win; } win;
#endif #endif
#if defined(SDL_VIDEO_DRIVER_X11) #if defined(SDL_VIDEO_DRIVER_X11)
struct { struct
{
XEvent event; XEvent event;
} x11; } x11;
#endif #endif
#if defined(SDL_VIDEO_DRIVER_DIRECTFB) #if defined(SDL_VIDEO_DRIVER_DIRECTFB)
struct { struct
{
DFBEvent event; DFBEvent event;
} dfb; } dfb;
#endif #endif
@ -353,7 +356,6 @@ struct SDL_SysWMinfo
typedef struct SDL_SysWMinfo SDL_SysWMinfo; typedef struct SDL_SysWMinfo SDL_SysWMinfo;
/** /**
* Get driver-specific information about a window. * Get driver-specific information about a window.
* *
@ -374,7 +376,6 @@ typedef struct SDL_SysWMinfo SDL_SysWMinfo;
extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window *window, extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window *window,
SDL_SysWMinfo *info); SDL_SysWMinfo *info);
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -4,8 +4,8 @@
#ifndef SDL_kolibriclipboard_h_ #ifndef SDL_kolibriclipboard_h_
#define SDL_kolibriclipboard_h_ #define SDL_kolibriclipboard_h_
extern char *KOLIBRI_GetClipboardText(_THIS); char *KOLIBRI_GetClipboardText(_THIS);
extern int KOLIBRI_SetClipboardText(_THIS, const char *text); int KOLIBRI_SetClipboardText(_THIS, const char *text);
extern SDL_bool KOLIBRI_HasClipboardText(_THIS); SDL_bool KOLIBRI_HasClipboardText(_THIS);
#endif /* SDL_kolibriclipboard_h_ */ #endif /* SDL_kolibriclipboard_h_ */

View File

@ -248,6 +248,7 @@ void KOLIBRI_PumpEvents(_THIS)
int top = 0; int top = 0;
int scancode = 0; int scancode = 0;
int pressed = 0; int pressed = 0;
int win_size_w, win_size_h;
SDL_Keycode keycode = SDLK_UNKNOWN; SDL_Keycode keycode = SDLK_UNKNOWN;
SDL_Keymod mod = 0; SDL_Keymod mod = 0;
static int ext_code = 0; static int ext_code = 0;
@ -262,24 +263,19 @@ void KOLIBRI_PumpEvents(_THIS)
return; return;
case KSYS_EVENT_REDRAW: case KSYS_EVENT_REDRAW:
{ {
top = _ksys_thread_info(&thread_info, KSYS_THIS_SLOT); _ksys_thread_info(&thread_info, KSYS_THIS_SLOT);
if (top == thread_info.pos_in_window_stack) {
int win_size_w = thread_info.winx_size;
int win_size_h = thread_info.winy_size;
if (wdata->skin == 0x01) { win_size_w = thread_info.winx_size + 1;
win_size_w++; win_size_h = thread_info.winy_size + 1;
win_size_h++; if (wdata->skin != 0x01) {
} else { win_size_w -= TRUE_WIN_WIDTH;
win_size_w -= (TRUE_WIN_WIDTH + 1); win_size_h -= TRUE_WIN_HEIGHT;
win_size_h -= (TRUE_WIN_HEIGHT + 1);
} }
if (thread_info.winx_start != window->x || thread_info.winy_start != window->y) if (thread_info.winx_start != window->x || thread_info.winy_start != window->y)
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, thread_info.winx_start, thread_info.winy_start); SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, thread_info.winx_start, thread_info.winy_start);
if (win_size_w != window->w || win_size_h != window->h) if (win_size_w != window->w || win_size_h != window->h)
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, win_size_w, win_size_h); SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, win_size_w, win_size_h);
}
if (thread_info.window_state & 0x01) { if (thread_info.window_state & 0x01) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0); SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
@ -344,6 +340,7 @@ void KOLIBRI_PumpEvents(_THIS)
{ {
mouse_pos = _ksys_get_mouse_pos(KSYS_MOUSE_WINDOW_POS); mouse_pos = _ksys_get_mouse_pos(KSYS_MOUSE_WINDOW_POS);
if (mouse_pos.x >= 0 && mouse_pos.x < window->w && mouse_pos.y >= 0 && mouse_pos.y < window->h || SDL_GetMouse()->relative_mode) { if (mouse_pos.x >= 0 && mouse_pos.x < window->w && mouse_pos.y >= 0 && mouse_pos.y < window->h || SDL_GetMouse()->relative_mode) {
if (SDL_GetMouse()->relative_mode) { if (SDL_GetMouse()->relative_mode) {
center_pos.x = mouse_pos.x - (window->w / 2); center_pos.x = mouse_pos.x - (window->w / 2);
center_pos.y = mouse_pos.y - (window->h / 2); center_pos.y = mouse_pos.y - (window->h / 2);

View File

@ -4,7 +4,7 @@
#include "../../SDL_internal.h" #include "../../SDL_internal.h"
extern void KOLIBRI_InitOSKeymap(void); void KOLIBRI_InitOSKeymap(void);
extern void KOLIBRI_PumpEvents(_THIS); void KOLIBRI_PumpEvents(_THIS);
#endif /* SDL_kolibrievents_h_ */ #endif /* SDL_kolibrievents_h_ */

View File

@ -23,7 +23,7 @@ int KOLIBRI_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, v
{ {
SDL_WindowData *data = (SDL_WindowData *)window->driverdata; SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
SDL_Surface *surface; SDL_Surface *surface;
const Uint32 surface_format = SDL_PIXELFORMAT_RGB24; const Uint32 surface_format = SDL_PIXELFORMAT_BGR24;
int w, h; int w, h;
/* Free the old framebuffer surface */ /* Free the old framebuffer surface */

View File

@ -4,8 +4,8 @@
#ifndef SDL_kolibriframebuffer_h_ #ifndef SDL_kolibriframebuffer_h_
#define SDL_kolibriframebuffer_h_ #define SDL_kolibriframebuffer_h_
extern int KOLIBRI_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch); int KOLIBRI_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch);
extern int KOLIBRI_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects); int KOLIBRI_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects);
extern void KOLIBRI_DestroyWindowFramebuffer(_THIS, SDL_Window *window); void KOLIBRI_DestroyWindowFramebuffer(_THIS, SDL_Window *window);
#endif /* SDL_kolibriframebuffer_h_ */ #endif /* SDL_kolibriframebuffer_h_ */

View File

@ -11,6 +11,6 @@ typedef struct _KOLIBRI_CursorData
void *null_cursor; void *null_cursor;
} KOLIBRI_CursorData; } KOLIBRI_CursorData;
extern void KOLIBRI_InitMouse(void); void KOLIBRI_InitMouse(void);
#endif /* SDL_kolibrimouse_h_ */ #endif /* SDL_kolibrimouse_h_ */

View File

@ -34,7 +34,7 @@ int KOLIBRI_VideoInit(_THIS)
screen_size = _ksys_screen_size(); screen_size = _ksys_screen_size();
/* Use 24-bpp desktop mode */ /* Use 24-bpp desktop mode */
mode.format = SDL_PIXELFORMAT_RGB24; mode.format = SDL_PIXELFORMAT_BGR24;
mode.w = screen_size.x + 1; mode.w = screen_size.x + 1;
mode.h = screen_size.y + 1; mode.h = screen_size.y + 1;
mode.refresh_rate = 60; mode.refresh_rate = 60;
@ -95,6 +95,13 @@ static SDL_VideoDevice *KOLIBRI_CreateDevice(void)
/* "Window" */ /* "Window" */
device->CreateSDLWindow = KOLIBRI_CreateWindow; device->CreateSDLWindow = KOLIBRI_CreateWindow;
device->MaximizeWindow = KOLIBRI_MaximizeWindow;
device->MinimizeWindow = KOLIBRI_MinimizeWindow;
device->RestoreWindow = KOLIBRI_RestoreWindow;
device->SetWindowFullscreen = KOLIBRI_SetWindowFullscreen;
device->SetWindowPosition = KOLIBRI_SetWindowPosition;
device->SetWindowResizable = KOLIBRI_SetWindowResizable;
device->SetWindowSize = KOLIBRI_SetWindowSize;
device->SetWindowTitle = KOLIBRI_SetWindowTitle; device->SetWindowTitle = KOLIBRI_SetWindowTitle;
device->DestroyWindow = KOLIBRI_DestroyWindow; device->DestroyWindow = KOLIBRI_DestroyWindow;

View File

@ -8,10 +8,13 @@
#include "../../events/SDL_keyboard_c.h" #include "../../events/SDL_keyboard_c.h"
#include "../../events/SDL_mouse_c.h" #include "../../events/SDL_mouse_c.h"
#include "../SDL_sysvideo.h" #include "../SDL_sysvideo.h"
#include "SDL_syswm.h"
#include "SDL_kolibrivideo.h" #include "SDL_kolibrivideo.h"
#include "SDL_kolibriwindow.h" #include "SDL_kolibriwindow.h"
static int pid = 0;
void KOLIBRI_RepaintWnd(_THIS) void KOLIBRI_RepaintWnd(_THIS)
{ {
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
@ -20,24 +23,20 @@ void KOLIBRI_RepaintWnd(_THIS)
int win_pos_x, win_pos_y; int win_pos_x, win_pos_y;
int win_size_w, win_size_h; int win_size_w, win_size_h;
win_size_w = window->w + TRUE_WIN_WIDTH; win_size_w = window->w;
win_size_h = window->h + TRUE_WIN_HEIGHT; win_size_h = window->h;
if (wdata->skin == 0x33 || wdata->skin == 0x34) {
win_size_w += TRUE_WIN_WIDTH;
win_size_h += TRUE_WIN_HEIGHT;
}
_ksys_start_draw(); _ksys_start_draw();
_ksys_create_window(window->x, window->y, win_size_w, win_size_h, window->title, 0, 0x34); _ksys_create_window(window->x, window->y, win_size_w, win_size_h, window->title, 0, wdata->skin);
if (wdata->surface->pixels) if (wdata->surface->pixels)
_ksys_draw_bitmap(wdata->surface->pixels, 0, 0, wdata->surface->w, wdata->surface->h); _ksys_draw_bitmap(wdata->surface->pixels, 0, 0, wdata->surface->w, wdata->surface->h);
_ksys_end_draw(); _ksys_end_draw();
} }
void KOLIBRI_change_window_size_and_pos(int w, int h, int x, int y)
{
w += TRUE_WIN_WIDTH;
h += TRUE_WIN_HEIGHT;
_ksys_change_window(x, y, w, h);
}
int KOLIBRI_CreateWindow(_THIS, SDL_Window *window) int KOLIBRI_CreateWindow(_THIS, SDL_Window *window)
{ {
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
@ -52,6 +51,7 @@ int KOLIBRI_CreateWindow(_THIS, SDL_Window *window)
window->driverdata = wdata; window->driverdata = wdata;
data->window_id = SDL_GetWindowID(window); data->window_id = SDL_GetWindowID(window);
wdata->skin = 0x34;
_ksys_set_event_mask(0x27); _ksys_set_event_mask(0x27);
KOLIBRI_RepaintWnd(_this); KOLIBRI_RepaintWnd(_this);
@ -61,14 +61,64 @@ int KOLIBRI_CreateWindow(_THIS, SDL_Window *window)
return 0; return 0;
} }
void KOLIBRI_MaximizeWindow(_THIS, SDL_Window *window)
{
// TODO
}
void KOLIBRI_MinimizeWindow(_THIS, SDL_Window *window)
{
ksys_thread_t thread_info;
_ksys_thread_info(&thread_info, KSYS_THIS_SLOT);
pid = thread_info.pid;
asm_inline("int $0x40" ::"a"(18), "b"(22), "c"(1), "d"(pid));
}
void KOLIBRI_RestoreWindow(_THIS, SDL_Window *window)
{
asm_inline("int $0x40" ::"a"(18), "b"(22), "c"(3), "d"(pid));
}
void KOLIBRI_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *_display, SDL_bool fullscreen)
{
SDL_WindowData *wdata = (SDL_WindowData *)window->driverdata;
static int old_w, old_h, old_x, old_y;
static unsigned char old_skin;
if (fullscreen) {
old_w = window->w + (TRUE_WIN_WIDTH - 1);
old_h = window->h + (TRUE_WIN_HEIGHT - 1);
old_x = window->x;
old_y = window->y;
old_skin = wdata->skin;
wdata->skin = 0x01;
_ksys_change_window(0, 0, _ksys_screen_size().x + 1, _ksys_screen_size().y + 1);
} else {
wdata->skin = old_skin;
_ksys_change_window(old_x, old_y, old_w, old_h);
}
}
void KOLIBRI_SetWindowPosition(_THIS, SDL_Window *window) void KOLIBRI_SetWindowPosition(_THIS, SDL_Window *window)
{ {
KOLIBRI_change_window_size_and_pos(window->w, window->h, window->x, window->y); _ksys_change_window(window->x, window->y, window->w + (TRUE_WIN_WIDTH - 1), window->h + (TRUE_WIN_HEIGHT - 1));
}
void KOLIBRI_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable)
{
SDL_WindowData *wdata = (SDL_WindowData *)window->driverdata;
if (resizable)
wdata->skin = 0x33;
else
wdata->skin = 0x34;
KOLIBRI_RepaintWnd(_this);
} }
void KOLIBRI_SetWindowSize(_THIS, SDL_Window *window) void KOLIBRI_SetWindowSize(_THIS, SDL_Window *window)
{ {
KOLIBRI_change_window_size_and_pos(window->w, window->h, window->x, window->y); _ksys_change_window(window->x, window->y, window->w + (TRUE_WIN_WIDTH - 1), window->h + (TRUE_WIN_HEIGHT - 1));
} }
void KOLIBRI_SetWindowTitle(_THIS, SDL_Window *window) void KOLIBRI_SetWindowTitle(_THIS, SDL_Window *window)
@ -83,4 +133,16 @@ void KOLIBRI_DestroyWindow(_THIS, SDL_Window *window)
SDL_free(window->driverdata); SDL_free(window->driverdata);
} }
SDL_bool KOLIBRI_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
{
/* What is the point of this? What information should be included? */
if (info->version.major == SDL_MAJOR_VERSION) {
info->subsystem = SDL_SYSWM_KOLIBRI;
return SDL_TRUE;
} else {
SDL_SetError("Application not compiled with SDL %d", SDL_MAJOR_VERSION);
return SDL_FALSE;
}
}
#endif /* SDL_VIDEO_DRIVER_KOLIBRI */ #endif /* SDL_VIDEO_DRIVER_KOLIBRI */

View File

@ -8,7 +8,7 @@
#define WINDOW_BORDER_H 4 #define WINDOW_BORDER_H 4
#define WINDOW_BORDER_W 9 #define WINDOW_BORDER_W 9
#define TRUE_WIN_HEIGHT _ksys_get_skin_height() + WINDOW_BORDER_H; #define TRUE_WIN_HEIGHT _ksys_get_skin_height() + WINDOW_BORDER_H
#define TRUE_WIN_WIDTH WINDOW_BORDER_W #define TRUE_WIN_WIDTH WINDOW_BORDER_W
typedef struct SDL_WindowData typedef struct SDL_WindowData
@ -17,9 +17,17 @@ typedef struct SDL_WindowData
unsigned char skin; unsigned char skin;
} SDL_WindowData; } SDL_WindowData;
extern void KOLIBRI_RepaintWnd(_THIS); void KOLIBRI_RepaintWnd(_THIS);
extern int KOLIBRI_CreateWindow(_THIS, SDL_Window *window); int KOLIBRI_CreateWindow(_THIS, SDL_Window *window);
extern void KOLIBRI_SetWindowTitle(_THIS, SDL_Window *window); void KOLIBRI_MaximizeWindow(_THIS, SDL_Window *window);
extern void KOLIBRI_DestroyWindow(_THIS, SDL_Window *window); void KOLIBRI_MinimizeWindow(_THIS, SDL_Window *window);
void KOLIBRI_RestoreWindow(_THIS, SDL_Window *window);
void KOLIBRI_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *_display, SDL_bool fullscreen);
void KOLIBRI_SetWindowPosition(_THIS, SDL_Window *window);
void KOLIBRI_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable);
void KOLIBRI_SetWindowSize(_THIS, SDL_Window *window);
void KOLIBRI_SetWindowTitle(_THIS, SDL_Window *window);
void KOLIBRI_DestroyWindow(_THIS, SDL_Window *window);
SDL_bool KOLIBRI_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info);
#endif /* SDL_kolibriwindow_h_ */ #endif /* SDL_kolibriwindow_h_ */