Initial port to Yutani (missing events)
This commit is contained in:
parent
5b5baf694e
commit
8fb1fa62b7
@ -21,9 +21,6 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* Being a null driver, there's no event stream. We just define stubs for
|
||||
most of the API. */
|
||||
|
||||
#include "SDL.h"
|
||||
#include "../../events/SDL_sysevents.h"
|
||||
#include "../../events/SDL_events_c.h"
|
||||
@ -31,7 +28,7 @@
|
||||
#include "SDL_toaruvideo.h"
|
||||
#include "SDL_toaruevents_c.h"
|
||||
|
||||
#include <toaru/window.h>
|
||||
#include <toaru/yutani.h>
|
||||
#include <toaru/kbd.h>
|
||||
|
||||
static SDLKey keymap[256];
|
||||
@ -40,129 +37,32 @@ static SDLMod modstate = KMOD_NONE;
|
||||
int mouse_state = 0;
|
||||
|
||||
void TOARU_PumpEvents(_THIS) {
|
||||
wins_packet_t * event = get_window_events_async();
|
||||
while (event) {
|
||||
switch (event->command_type & WE_GROUP_MASK) {
|
||||
case WE_WINDOW_EVT:
|
||||
yutani_msg_t * m;
|
||||
do {
|
||||
m = yutani_poll_async(this->hidden->yctx);
|
||||
|
||||
if (!m) break;
|
||||
|
||||
switch (m->type) {
|
||||
case YUTANI_MSG_KEY_EVENT:
|
||||
{
|
||||
w_window_t * evt = (w_window_t *)((uintptr_t)event + sizeof(wins_packet_t));
|
||||
window_t * window = NULL;
|
||||
switch (event->command_type) {
|
||||
case WE_RESIZED:
|
||||
fprintf(stderr, "[SDL] Received RESIZE message from server.\n");
|
||||
if (this->hidden->triggered_resize != 2) {
|
||||
fprintf(stderr, "--- From a natural resize. Informing SDL.\n");
|
||||
this->hidden->triggered_resize = 1;
|
||||
SDL_PrivateResize(evt->width - this->hidden->x_w, evt->height - this->hidden->x_h);
|
||||
} else {
|
||||
this->hidden->triggered_resize = 0;
|
||||
}
|
||||
break;
|
||||
case WE_FOCUSCHG:
|
||||
window = wins_get_window(evt->wid);
|
||||
if (window) {
|
||||
window->focused = evt->left;
|
||||
}
|
||||
this->hidden->redraw_borders = 1;
|
||||
SDL_PrivateAppActive(0, evt->left);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WE_KEY_EVT:
|
||||
{
|
||||
w_keyboard_t * kbd = (w_keyboard_t *)((uintptr_t)event + sizeof(wins_packet_t));
|
||||
if (kbd->event.keycode) {
|
||||
SDL_keysym keysym;
|
||||
int action = kbd->event.action == KEY_ACTION_DOWN ? SDL_PRESSED : SDL_RELEASED;
|
||||
keysym.scancode = kbd->event.keycode;
|
||||
keysym.unicode = 0;
|
||||
keysym.mod = KMOD_NONE;
|
||||
switch (kbd->event.keycode) {
|
||||
case '\n':
|
||||
keysym.sym = SDLK_RETURN;
|
||||
SDL_PrivateKeyboard(action, &keysym);
|
||||
break;
|
||||
case ' ':
|
||||
keysym.sym = SDLK_SPACE;
|
||||
SDL_PrivateKeyboard(action, &keysym);
|
||||
break;
|
||||
case KEY_ARROW_UP:
|
||||
keysym.sym = SDLK_UP;
|
||||
SDL_PrivateKeyboard(action, &keysym);
|
||||
break;
|
||||
case KEY_ARROW_LEFT:
|
||||
keysym.sym = SDLK_LEFT;
|
||||
SDL_PrivateKeyboard(action, &keysym);
|
||||
break;
|
||||
case KEY_ARROW_RIGHT:
|
||||
keysym.sym = SDLK_RIGHT;
|
||||
SDL_PrivateKeyboard(action, &keysym);
|
||||
break;
|
||||
case KEY_ARROW_DOWN:
|
||||
keysym.sym = SDLK_DOWN;
|
||||
SDL_PrivateKeyboard(action, &keysym);
|
||||
break;
|
||||
case KEY_ESCAPE:
|
||||
keysym.sym = SDLK_ESCAPE;
|
||||
SDL_PrivateKeyboard(action, &keysym);
|
||||
break;
|
||||
case KEY_BACKSPACE:
|
||||
keysym.sym = SDLK_BACKSPACE;
|
||||
SDL_PrivateKeyboard(action, &keysym);
|
||||
break;
|
||||
case '\t':
|
||||
keysym.sym = SDLK_TAB;
|
||||
SDL_PrivateKeyboard(action, &keysym);
|
||||
break;
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e':
|
||||
case 'f': case 'g': case 'h': case 'i': case 'j':
|
||||
case 'k': case 'l': case 'm': case 'n': case 'o':
|
||||
case 'p': case 'q': case 'r': case 's': case 't':
|
||||
case 'u': case 'v': case 'w': case 'x': case 'y':
|
||||
case 'z':
|
||||
case ':': case ';': case '<': case '=': case '>':
|
||||
case '?': case '@': case '[': case ']': case '\\':
|
||||
case '^': case '_': case '`': case '.': case '/':
|
||||
case '*': case '-': case '+': case '#': case '"':
|
||||
case '!': case '&': case '$': case '(': case '\'':
|
||||
keysym.sym = (kbd->event.keycode - 'a' + SDLK_a);
|
||||
SDL_PrivateKeyboard(action, &keysym);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "[SDL] Key press: %d ('%c')\n", kbd->event.keycode, kbd->key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WE_MOUSE_EVT:
|
||||
{
|
||||
w_mouse_t * mouse = (w_mouse_t *)((uintptr_t)event + sizeof(wins_packet_t));
|
||||
int i;
|
||||
signed short x = mouse->new_x - this->hidden->o_w;
|
||||
signed short y = mouse->new_y - this->hidden->o_h;
|
||||
for (i = 0; i < 3; ++i) {
|
||||
int was = mouse_state & (1 << i);
|
||||
int is = mouse->buttons & (1 << i);
|
||||
if (is && (was != is)) {
|
||||
SDL_PrivateMouseButton(SDL_PRESSED, i + 1, x, y);
|
||||
} else if ((was) && (was != is)) {
|
||||
SDL_PrivateMouseButton(SDL_RELEASED, i + 1, x, y);
|
||||
} else if (was != is) {
|
||||
SDL_PrivateMouseButton(SDL_RELEASED, i + 1, x, y);
|
||||
}
|
||||
mouse_state = mouse->buttons;
|
||||
}
|
||||
SDL_PrivateMouseMotion(0, 0, x, y);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case YUTANI_MSG_WINDOW_FOCUS_CHANGE:
|
||||
case YUTANI_MSG_RESIZE_OFFER:
|
||||
case YUTANI_MSG_WINDOW_MOUSE_EVENT:
|
||||
case YUTANI_MSG_SESSION_END:
|
||||
fprintf(stderr, "[sdl-toaru] Need to implement: %u\n", (unsigned int)m->type);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "[sdl-toaru] Unhandled message from Yutani server: type=0x%x\n", (unsigned int)m->type);
|
||||
break;
|
||||
}
|
||||
free(event);
|
||||
event = get_window_events_async();
|
||||
}
|
||||
|
||||
free(m);
|
||||
} while (m);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TOARU_InitOSKeymap(_THIS)
|
||||
|
@ -46,7 +46,7 @@
|
||||
#include "SDL_toaruevents_c.h"
|
||||
#include "SDL_toarumouse_c.h"
|
||||
|
||||
#include <toaru/window.h>
|
||||
#include <toaru/yutani.h>
|
||||
#include <toaru/graphics.h>
|
||||
#include <toaru/decorations.h>
|
||||
|
||||
@ -147,7 +147,7 @@ int TOARU_VideoInit(_THIS, SDL_PixelFormat *vformat)
|
||||
vformat->BitsPerPixel = 32;
|
||||
vformat->BytesPerPixel = 4;
|
||||
|
||||
setup_windowing();
|
||||
this->hidden->yctx = yutani_init();
|
||||
init_decorations();
|
||||
this->hidden->triggered_resize = 0;
|
||||
|
||||
@ -160,11 +160,10 @@ SDL_Rect **TOARU_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
|
||||
return (SDL_Rect **) -1;
|
||||
}
|
||||
|
||||
extern void wins_send_command(wid_t, int16_t, int16_t, uint16_t, uint16_t, int, int);
|
||||
|
||||
SDL_Surface *TOARU_SetVideoMode(_THIS, SDL_Surface *current,
|
||||
int width, int height, int bpp, Uint32 flags)
|
||||
{
|
||||
#if 0
|
||||
if ( this->hidden->window) {
|
||||
fprintf(stderr, "Resize request to %d x %d.\n", width, height);
|
||||
|
||||
@ -189,6 +188,7 @@ SDL_Surface *TOARU_SetVideoMode(_THIS, SDL_Surface *current,
|
||||
this->hidden->redraw_borders = 1;
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
|
||||
if (flags & SDL_NOFRAME) {
|
||||
fprintf(stderr, "Initializing without borders.\n");
|
||||
@ -208,10 +208,10 @@ SDL_Surface *TOARU_SetVideoMode(_THIS, SDL_Surface *current,
|
||||
}
|
||||
|
||||
fprintf(stderr, "Initializing window %dx%d (%d bpp)\n", width, height, bpp);
|
||||
window_t * win = window_create(100, 100, width + this->hidden->x_w, height + this->hidden->x_h);
|
||||
win_sane_events();
|
||||
|
||||
gfx_context_t * ctx = init_graphics_window_double_buffer(win);
|
||||
yutani_window_t * win = yutani_window_create(this->hidden->yctx, width + this->hidden->x_w, height + this->hidden->x_h);
|
||||
|
||||
gfx_context_t * ctx = init_graphics_yutani_double_buffer(win);
|
||||
this->hidden->window = (void *)win;
|
||||
this->hidden->ctx = (void *)ctx;
|
||||
|
||||
@ -223,7 +223,9 @@ SDL_Surface *TOARU_SetVideoMode(_THIS, SDL_Surface *current,
|
||||
|
||||
|
||||
fprintf(stderr, "Window output initialized...\n");
|
||||
#if 0
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set up the new mode framebuffer */
|
||||
current->flags = flags;
|
||||
@ -289,6 +291,7 @@ static void TOARU_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
|
||||
}
|
||||
flip(this->hidden->ctx);
|
||||
}
|
||||
yutani_flip(this->hidden->yctx, this->hidden->window);
|
||||
|
||||
}
|
||||
|
||||
@ -303,7 +306,7 @@ int TOARU_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
|
||||
*/
|
||||
void TOARU_VideoQuit(_THIS)
|
||||
{
|
||||
teardown_windowing();
|
||||
/* XXX close windows */
|
||||
}
|
||||
|
||||
static void TOARU_SetCaption(_THIS, const char *title, const char *icon) {
|
||||
|
@ -29,14 +29,16 @@
|
||||
/* Hidden "this" pointer for the video functions */
|
||||
#define _THIS SDL_VideoDevice *this
|
||||
|
||||
#include <toaru/yutani.h>
|
||||
|
||||
/* Private display data */
|
||||
|
||||
struct SDL_PrivateVideoData {
|
||||
yutani_t * yctx;
|
||||
int w, h;
|
||||
void *buffer;
|
||||
void *window;
|
||||
void *ctx;
|
||||
void * buffer;
|
||||
void * window;
|
||||
void * ctx;
|
||||
int bordered;
|
||||
char * title;
|
||||
int x_w, x_h;
|
||||
|
Loading…
x
Reference in New Issue
Block a user