Skip to content

Commit

Permalink
Map more keys, fix mouse wheel, add stub subsurface support, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
X547 committed Aug 18, 2022
1 parent 210b520 commit 15a5226
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 13 deletions.
7 changes: 3 additions & 4 deletions HaikuCompositor.cpp
Expand Up @@ -50,7 +50,7 @@ void HaikuRegion::HandleSubtract(int32_t x, int32_t y, int32_t width, int32_t he
}


//#pragma mark - compositor
//#pragma mark - HaikuCompositor

struct wl_global *HaikuCompositor::CreateGlobal(struct wl_display *display)
{
Expand Down Expand Up @@ -151,7 +151,6 @@ HaikuSurface *HaikuSurface::Create(struct wl_client *client, uint32_t version, u
if (!surface->Init(client, version, id)) {
return NULL;
}
surface->fClient = client;
return surface;
}

Expand Down Expand Up @@ -208,9 +207,9 @@ void HaikuSurface::HandleDamage(int32_t x, int32_t y, int32_t width, int32_t hei

void HaikuSurface::HandleFrame(uint32_t callback_id)
{
fCallback = wl_resource_create(fClient, &wl_callback_interface, 1, callback_id);
fCallback = wl_resource_create(Client(), &wl_callback_interface, 1, callback_id);
if (fCallback == NULL) {
wl_client_post_no_memory(fClient);
wl_client_post_no_memory(Client());
return;
}
}
Expand Down
1 change: 0 additions & 1 deletion HaikuCompositor.h
Expand Up @@ -57,7 +57,6 @@ class HaikuSurface: public WlSurface {
int32_t scale = 1;
};

struct wl_client *fClient;
ObjectDeleter<Hook> fHook;

State fState;
Expand Down
24 changes: 16 additions & 8 deletions HaikuSeat.cpp
Expand Up @@ -71,7 +71,7 @@ static uint32_t FromHaikuKeyCode(uint32 haikuKey)
case 0x30: wlKey = KEY_P; break;
case 0x31: wlKey = KEY_LEFTBRACE; break;
case 0x32: wlKey = KEY_RIGHTBRACE; break;
//case 0x33: wlKey = VK_OEM_6; break;
case 0x33: wlKey = KEY_BACKSLASH; break;
case 0x34: wlKey = KEY_DELETE; break;

case 0x3b: wlKey = KEY_CAPSLOCK; break;
Expand All @@ -84,8 +84,8 @@ static uint32_t FromHaikuKeyCode(uint32 haikuKey)
case 0x42: wlKey = KEY_J; break;
case 0x43: wlKey = KEY_K; break;
case 0x44: wlKey = KEY_L; break;
//case 0x45: wlKey = VK_OEM_PLUS; break;
//case 0x46: wlKey = VK_OEM_1; break;
case 0x45: wlKey = KEY_SEMICOLON; break;
case 0x46: wlKey = KEY_APOSTROPHE; break;
case 0x47: wlKey = KEY_ENTER; break;

case 0x4b: wlKey = KEY_LEFTSHIFT; break;
Expand All @@ -102,21 +102,25 @@ static uint32_t FromHaikuKeyCode(uint32 haikuKey)
case 0x56: wlKey = KEY_RIGHTSHIFT; break;
case 0x57: wlKey = KEY_UP; break;

//case 0x5c: wlKey = VK_LCONTROL; break;
//case 0x5d: wlKey = VK_LMENU; break;
case 0x5c: wlKey = KEY_LEFTCTRL; break;
case 0x5d: wlKey = KEY_LEFTALT; break;
case 0x5e: wlKey = KEY_SPACE; break;
case 0x5f: wlKey = KEY_RIGHTALT; break;

case 0x60: wlKey = KEY_RIGHTCTRL; break;
case 0x61: wlKey = KEY_LEFT; break;
case 0x62: wlKey = KEY_DOWN; break;
case 0x63: wlKey = KEY_RIGHT; break;

//case 0x66: wlKey = VK_LWIN; break;
//case 0x68: wlKey = VK_APPS; break;

//case 0x6a: wlKey = VK_OEM_5; break;
//case 0x6b: wlKey = VK_OEM_102; break;
case 0x6a: wlKey = KEY_RO; break;
case 0x6b: wlKey = KEY_102ND; break;

default: wlKey = 0;
default:
fprintf(stderr, "[!] unknown key: %#x\n", haikuKey);
wlKey = 0;
}
return wlKey;
}
Expand Down Expand Up @@ -286,15 +290,19 @@ bool HaikuSeat::MessageReceived(HaikuSurface *surface, BMessage *msg)
}
case B_MOUSE_WHEEL_CHANGED: {
if (fPointer == NULL || fPointerFocus != surface) return false;
bigtime_t when;
float dx, dy;
if (msg->FindInt64("when", &when) < B_OK) when = system_time();
if (msg->FindFloat("be:wheel_delta_x", &dx) < B_OK) dx = 0;
if (msg->FindFloat("be:wheel_delta_y", &dy) < B_OK) dy = 0;
if (dx != 0) {
fPointer->SendAxisSource(WlPointer::axisSourceWheel);
fPointer->SendAxis(when/1000, WlPointer::axisHorizontalScroll, wl_fixed_from_double(dx*10.0));
fPointer->SendAxisDiscrete(WlPointer::axisHorizontalScroll, dx);
}
if (dy != 0) {
fPointer->SendAxisSource(WlPointer::axisSourceWheel);
fPointer->SendAxis(when/1000, WlPointer::axisVerticalScroll, wl_fixed_from_double(dy*10.0));
fPointer->SendAxisDiscrete(WlPointer::axisVerticalScroll, dy);
}
fPointer->SendFrame();
Expand Down
63 changes: 63 additions & 0 deletions HaikuSubcompositor.cpp
@@ -0,0 +1,63 @@
#include "HaikuSubcompositor.h"

extern const struct wl_interface wl_subcompositor_interface;


#define SUBCOMPOSITOR_VERSION 1


//#pragma mark - HaikuSubcompositor

struct wl_global *HaikuSubcompositor::CreateGlobal(struct wl_display *display)
{
return wl_global_create(display, &wl_subcompositor_interface, SUBCOMPOSITOR_VERSION, NULL, HaikuSubcompositor::Bind);
}

void HaikuSubcompositor::Bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id)
{
HaikuSubcompositor *manager = new(std::nothrow) HaikuSubcompositor();
if (manager == NULL) {
wl_client_post_no_memory(wl_client);
return;
}
if (!manager->Init(wl_client, version, id)) {
return;
}
}

void HaikuSubcompositor::HandleGetSubsurface(uint32_t id, struct wl_resource *surface, struct wl_resource *parent)
{
HaikuSubsurface *subsurface = HaikuSubsurface::Create(Client(), wl_resource_get_version(ToResource()), id);
}


//#pragma mark - HaikuSubsurface

HaikuSubsurface *HaikuSubsurface::Create(struct wl_client *client, uint32_t version, uint32_t id)
{
HaikuSubsurface *surface = new(std::nothrow) HaikuSubsurface();
if (!surface->Init(client, version, id)) {
return NULL;
}
return surface;
}

void HaikuSubsurface::HandleSetPosition(int32_t x, int32_t y)
{
}

void HaikuSubsurface::HandlePlaceAbove(struct wl_resource *sibling)
{
}

void HaikuSubsurface::HandlePlaceBelow(struct wl_resource *sibling)
{
}

void HaikuSubsurface::HandleSetSync()
{
}

void HaikuSubsurface::HandleSetDesync()
{
}
25 changes: 25 additions & 0 deletions HaikuSubcompositor.h
@@ -0,0 +1,25 @@
#pragma once

#include "Wayland.h"


class HaikuSubcompositor: public WlSubcompositor {
public:
static void Bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id);

public:
static struct wl_global *CreateGlobal(struct wl_display *display);
static HaikuSubcompositor *FromResource(struct wl_resource *resource) {return (HaikuSubcompositor*)WlResource::FromResource(resource);}

void HandleGetSubsurface(uint32_t id, struct wl_resource *surface, struct wl_resource *parent) final;
};

class HaikuSubsurface: public WlSubsurface {
public:
static HaikuSubsurface *Create(struct wl_client *client, uint32_t version, uint32_t id);
void HandleSetPosition(int32_t x, int32_t y) final;
void HandlePlaceAbove(struct wl_resource *sibling) final;
void HandlePlaceBelow(struct wl_resource *sibling) final;
void HandleSetSync() final;
void HandleSetDesync() final;
};
2 changes: 2 additions & 0 deletions WaylandServer.cpp
@@ -1,5 +1,6 @@
#include "Wayland.h"
#include "HaikuCompositor.h"
#include "HaikuSubcompositor.h"
#include "HaikuXdgShell.h"
#include "HaikuXdgSurface.h"
#include "HaikuXdgToplevel.h"
Expand Down Expand Up @@ -101,6 +102,7 @@ extern "C" _EXPORT int wl_ips_client_connected(void **clientOut, void *clientDis

Assert(wl_display_init_shm(display) == 0);
Assert(HaikuCompositor::CreateGlobal(display) != NULL);
Assert(HaikuSubcompositor::CreateGlobal(display) != NULL);
Assert(HaikuOutput::CreateGlobal(display) != NULL);
Assert(HaikuDataDeviceManager::CreateGlobal(display) != NULL);
Assert(HaikuSeat::CreateGlobal(display) != NULL);
Expand Down
1 change: 1 addition & 0 deletions meson.build
Expand Up @@ -94,6 +94,7 @@ shared_library('wayland-server-inproc',
'WaylandServer.cpp',
'WlResource.cpp',
'HaikuCompositor.cpp',
'HaikuSubcompositor.cpp',
'HaikuXdgShell.cpp',
'HaikuXdgPositioner.cpp',
'HaikuXdgSurface.cpp',
Expand Down

0 comments on commit 15a5226

Please sign in to comment.