Move windows to uptr. Add simple text editing.
This commit is contained in:
parent
2bcc7b3d83
commit
b99708e7d3
55 changed files with 1257 additions and 994 deletions
|
@ -16,15 +16,15 @@
|
|||
|
||||
|
||||
XcbInterface::XcbInterface()
|
||||
: mUseOpenGl(true),
|
||||
mConnection(nullptr),
|
||||
mScreen(nullptr),
|
||||
mWindows(),
|
||||
mHandles(),
|
||||
mDefaultWindow(-1),
|
||||
mGraphicsContext(-1),
|
||||
mX11Display(),
|
||||
mGlxInterface()
|
||||
: mUseOpenGl(true),
|
||||
mConnection(nullptr),
|
||||
mScreen(nullptr),
|
||||
mWindows(),
|
||||
mHandles(),
|
||||
mDefaultWindow(-1),
|
||||
mGraphicsContext(-1),
|
||||
mX11Display(),
|
||||
mGlxInterface()
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -36,313 +36,314 @@ XcbInterface::~XcbInterface()
|
|||
|
||||
void XcbInterface::SetUseOpenGl(bool use)
|
||||
{
|
||||
mUseOpenGl = use;
|
||||
mUseOpenGl = use;
|
||||
}
|
||||
|
||||
void XcbInterface::Initialize()
|
||||
{
|
||||
Connect();
|
||||
UpdateScreen();
|
||||
CreateGraphicsContext();
|
||||
Connect();
|
||||
UpdateScreen();
|
||||
CreateGraphicsContext();
|
||||
|
||||
if(mUseOpenGl)
|
||||
{
|
||||
InitializeOpenGl();
|
||||
}
|
||||
if(mUseOpenGl)
|
||||
{
|
||||
InitializeOpenGl();
|
||||
}
|
||||
}
|
||||
|
||||
void XcbInterface::Connect()
|
||||
{
|
||||
if(mUseOpenGl)
|
||||
{
|
||||
/* Open Xlib Display */
|
||||
mX11Display = XOpenDisplay(0);
|
||||
if(!mX11Display)
|
||||
{
|
||||
std::cerr << "Can't open X11 display" << std::endl;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Got display" << std::endl;
|
||||
}
|
||||
if(mUseOpenGl)
|
||||
{
|
||||
/* Open Xlib Display */
|
||||
mX11Display = XOpenDisplay(0);
|
||||
if(!mX11Display)
|
||||
{
|
||||
std::cerr << "Can't open X11 display" << std::endl;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Got display" << std::endl;
|
||||
}
|
||||
|
||||
/* Get the XCB connection from the display */
|
||||
mConnection = XGetXCBConnection(mX11Display);
|
||||
if(!mConnection)
|
||||
{
|
||||
XCloseDisplay(mX11Display);
|
||||
std::cerr << "Can't get xcb connection from display" << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cout << "Got connection" << std::endl;
|
||||
/* Get the XCB connection from the display */
|
||||
mConnection = XGetXCBConnection(mX11Display);
|
||||
if(!mConnection)
|
||||
{
|
||||
XCloseDisplay(mX11Display);
|
||||
std::cerr << "Can't get xcb connection from display" << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cout << "Got connection" << std::endl;
|
||||
|
||||
/* Acquire event queue ownership */
|
||||
XSetEventQueueOwner(mX11Display, XCBOwnsEventQueue);
|
||||
}
|
||||
else
|
||||
{
|
||||
mConnection = xcb_connect(nullptr, nullptr);
|
||||
}
|
||||
/* Acquire event queue ownership */
|
||||
XSetEventQueueOwner(mX11Display, XCBOwnsEventQueue);
|
||||
}
|
||||
else
|
||||
{
|
||||
mConnection = xcb_connect(nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void XcbInterface::UpdateScreen()
|
||||
{
|
||||
if(!mConnection) return;
|
||||
if(!mConnection) return;
|
||||
|
||||
auto screen_iter = xcb_setup_roots_iterator(xcb_get_setup(mConnection));
|
||||
if(mUseOpenGl)
|
||||
{
|
||||
if(!mX11Display) return;
|
||||
int default_screen = DefaultScreen(mX11Display);
|
||||
for(int screen_num = default_screen;
|
||||
screen_iter.rem && screen_num > 0;
|
||||
--screen_num, xcb_screen_next(&screen_iter));
|
||||
}
|
||||
mScreen = screen_iter.data;
|
||||
auto screen_iter = xcb_setup_roots_iterator(xcb_get_setup(mConnection));
|
||||
if(mUseOpenGl)
|
||||
{
|
||||
if(!mX11Display) return;
|
||||
int default_screen = DefaultScreen(mX11Display);
|
||||
for(int screen_num = default_screen;
|
||||
screen_iter.rem && screen_num > 0;
|
||||
--screen_num, xcb_screen_next(&screen_iter));
|
||||
}
|
||||
mScreen = screen_iter.data;
|
||||
}
|
||||
|
||||
void XcbInterface::InitializeOpenGl()
|
||||
{
|
||||
mGlxInterface = GlxInterface::Create();
|
||||
int default_screen = DefaultScreen(mX11Display);
|
||||
mGlxInterface->SetupContext(mX11Display, default_screen);
|
||||
mGlxInterface = GlxInterface::Create();
|
||||
int default_screen = DefaultScreen(mX11Display);
|
||||
mGlxInterface->SetupContext(mX11Display, default_screen);
|
||||
}
|
||||
|
||||
void XcbInterface::CreateOpenGlDrawable(WindowPtr window)
|
||||
void XcbInterface::CreateOpenGlDrawable(mt::Window* window)
|
||||
{
|
||||
if(!mUseOpenGl)
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto hwnd = mHandles[window];
|
||||
bool result = mGlxInterface->SetupWindow(mX11Display, hwnd);
|
||||
if(!result)
|
||||
{
|
||||
xcb_destroy_window(mConnection, hwnd);
|
||||
}
|
||||
if(!mUseOpenGl or !window)
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto hwnd = mHandles[window];
|
||||
bool result = mGlxInterface->SetupWindow(mX11Display, hwnd);
|
||||
if(!result)
|
||||
{
|
||||
xcb_destroy_window(mConnection, hwnd);
|
||||
}
|
||||
}
|
||||
|
||||
void XcbInterface::CreateGraphicsContext()
|
||||
{
|
||||
if(!mConnection || !mScreen) return;
|
||||
mGraphicsContext = xcb_generate_id(mConnection);
|
||||
if(!mConnection || !mScreen) return;
|
||||
mGraphicsContext = xcb_generate_id(mConnection);
|
||||
|
||||
xcb_drawable_t window = mScreen->root;
|
||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
||||
uint32_t values[2] = {XcbLayerInterface::GetColor(240, 240, 240), 0};
|
||||
xcb_create_gc(mConnection, mGraphicsContext, window, mask, values);
|
||||
xcb_drawable_t window = mScreen->root;
|
||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
||||
uint32_t values[2] = {XcbLayerInterface::GetColor(240, 240, 240), 0};
|
||||
xcb_create_gc(mConnection, mGraphicsContext, window, mask, values);
|
||||
}
|
||||
|
||||
void XcbInterface::MapWindow(WindowPtr window)
|
||||
void XcbInterface::MapWindow(mt::Window* window)
|
||||
{
|
||||
if(!mConnection) return;
|
||||
xcb_map_window(mConnection, mHandles[window]);
|
||||
xcb_flush(mConnection);
|
||||
if(!mConnection or !window) return;
|
||||
xcb_map_window(mConnection, mHandles[window]);
|
||||
xcb_flush(mConnection);
|
||||
}
|
||||
|
||||
void XcbInterface::ShowWindow(WindowPtr window)
|
||||
void XcbInterface::ShowWindow(mt::Window* window)
|
||||
{
|
||||
MapWindow(window);
|
||||
MapWindow(window);
|
||||
}
|
||||
|
||||
uint32_t XcbInterface::GetEventMask()
|
||||
{
|
||||
return XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS |
|
||||
XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_POINTER_MOTION;
|
||||
return XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS |
|
||||
XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_POINTER_MOTION;
|
||||
}
|
||||
|
||||
void XcbInterface::AddWindow(WindowPtr window)
|
||||
void XcbInterface::AddWindow(mt::Window* window)
|
||||
{
|
||||
if(!mConnection || !mScreen) return;
|
||||
auto hwnd = xcb_generate_id(mConnection);
|
||||
if(!mConnection || !mScreen || !window) return;
|
||||
auto hwnd = xcb_generate_id(mConnection);
|
||||
|
||||
uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
|
||||
uint32_t values[2] = {mScreen->white_pixel, GetEventMask()};
|
||||
uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
|
||||
uint32_t values[2] = {mScreen->white_pixel, GetEventMask()};
|
||||
|
||||
xcb_create_window (mConnection, /* connection */
|
||||
XCB_COPY_FROM_PARENT, /* depth */
|
||||
hwnd, /* window Id */
|
||||
mScreen->root, /* parent window */
|
||||
0, 0, /* x, y */
|
||||
window->GetWidth(), window->GetHeight(), /* width, height */
|
||||
10, /* border_width */
|
||||
XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
|
||||
mScreen->root_visual, /* visual */
|
||||
mask, values ); /* masks */
|
||||
mWindows[hwnd] = window;
|
||||
mHandles[window] = hwnd;
|
||||
mDefaultWindow = hwnd;
|
||||
xcb_create_window (mConnection, /* connection */
|
||||
XCB_COPY_FROM_PARENT, /* depth */
|
||||
hwnd, /* window Id */
|
||||
mScreen->root, /* parent window */
|
||||
0, 0, /* x, y */
|
||||
window->GetWidth(), window->GetHeight(), /* width, height */
|
||||
10, /* border_width */
|
||||
XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
|
||||
mScreen->root_visual, /* visual */
|
||||
mask, values ); /* masks */
|
||||
mWindows[hwnd] = window;
|
||||
mHandles[window] = hwnd;
|
||||
mDefaultWindow = hwnd;
|
||||
}
|
||||
|
||||
void XcbInterface::onPaint(DesktopManagerPtr desktopManager)
|
||||
void XcbInterface::onPaint(DesktopManager* desktopManager)
|
||||
{
|
||||
auto ui_event = PaintEvent::Create();
|
||||
desktopManager->OnUiEvent(ui_event);
|
||||
|
||||
PaintWindow(desktopManager->GetWindowManager()->GetMainWindow());
|
||||
desktopManager->OnUiEvent(PaintEvent::Create());
|
||||
PaintWindow(desktopManager->GetWindowManager()->GetMainWindow());
|
||||
}
|
||||
|
||||
void XcbInterface::PaintWindow(WindowPtr window)
|
||||
void XcbInterface::PaintWindow(mt::Window* window)
|
||||
{
|
||||
const auto hwnd = mHandles[window];
|
||||
for(const auto& layer : window->GetLayers())
|
||||
{
|
||||
XcbLayerInterface::AddLayer(mConnection, mScreen,
|
||||
hwnd, mGraphicsContext, layer);
|
||||
}
|
||||
if(!window) return;
|
||||
|
||||
const auto hwnd = mHandles[window];
|
||||
for(const auto& layer : window->GetLayers())
|
||||
{
|
||||
XcbLayerInterface::AddLayer(mConnection, mScreen,
|
||||
hwnd, mGraphicsContext, layer);
|
||||
}
|
||||
}
|
||||
|
||||
void XcbInterface::OnKeyPress(xcb_key_press_event_t* event, DesktopManagerPtr desktopManager)
|
||||
void XcbInterface::OnKeyPress(xcb_key_press_event_t* event, DesktopManager* desktopManager)
|
||||
{
|
||||
auto ui_event = KeyboardEvent::Create();
|
||||
ui_event->SetAction(KeyboardEvent::Action::Pressed);
|
||||
std::string keyVal = desktopManager->GetKeyboard()->GetKeyString(event->detail);
|
||||
ui_event->SetKeyString(keyVal);
|
||||
desktopManager->OnUiEvent(ui_event);
|
||||
auto ui_event = KeyboardEvent::Create();
|
||||
ui_event->SetAction(KeyboardEvent::Action::Pressed);
|
||||
std::string keyVal = desktopManager->GetKeyboard()->GetKeyString(event->detail);
|
||||
ui_event->SetKeyString(keyVal);
|
||||
desktopManager->OnUiEvent(std::move(ui_event));
|
||||
}
|
||||
|
||||
void XcbInterface::OnKeyRelease(xcb_key_release_event_t* event, DesktopManagerPtr desktopManager)
|
||||
void XcbInterface::OnKeyRelease(xcb_key_release_event_t* event, DesktopManager* desktopManager)
|
||||
{
|
||||
auto ui_event = KeyboardEvent::Create();
|
||||
ui_event->SetAction(KeyboardEvent::Action::Released);
|
||||
std::string keyVal = desktopManager->GetKeyboard()->GetKeyString(event->detail);
|
||||
ui_event->SetKeyString(keyVal);
|
||||
desktopManager->OnUiEvent(ui_event);
|
||||
auto ui_event = KeyboardEvent::Create();
|
||||
ui_event->SetAction(KeyboardEvent::Action::Released);
|
||||
std::string keyVal = desktopManager->GetKeyboard()->GetKeyString(event->detail);
|
||||
ui_event->SetKeyString(keyVal);
|
||||
desktopManager->OnUiEvent(std::move(ui_event));
|
||||
}
|
||||
|
||||
void XcbInterface::OnButtonPress(xcb_button_press_event_t* event, DesktopManagerPtr desktopManager)
|
||||
void XcbInterface::OnButtonPress(xcb_button_press_event_t* event, DesktopManager* desktopManager)
|
||||
{
|
||||
auto ui_event = MouseEvent::Create();
|
||||
auto ui_event = MouseEvent::Create();
|
||||
auto x = static_cast<unsigned>(event->event_x);
|
||||
auto y = static_cast<unsigned>(event->event_y);
|
||||
ui_event->SetClientLocation(DiscretePoint(x, y));
|
||||
ui_event->SetClientLocation(DiscretePoint(x, y));
|
||||
|
||||
auto screen_x = static_cast<unsigned>(event->root_x);
|
||||
auto screen_y = static_cast<unsigned>(event->root_y);
|
||||
ui_event->SetScreenLocation(DiscretePoint(x, y));
|
||||
|
||||
ui_event->SetAction(MouseEvent::Action::Pressed);
|
||||
desktopManager->OnUiEvent(ui_event);
|
||||
ui_event->SetAction(MouseEvent::Action::Pressed);
|
||||
desktopManager->OnUiEvent(std::move(ui_event));
|
||||
}
|
||||
|
||||
void XcbInterface::LoopOpenGl(std::shared_ptr<DesktopManager> desktopManager)
|
||||
void XcbInterface::LoopOpenGl(DesktopManager* desktopManager)
|
||||
{
|
||||
int running = 1;
|
||||
while(running)
|
||||
{
|
||||
/* Wait for event */
|
||||
xcb_generic_event_t *event = xcb_wait_for_event(mConnection);
|
||||
if(!event)
|
||||
{
|
||||
std::cout << "i/o error in xcb_wait_for_event" << std::endl;
|
||||
return;
|
||||
}
|
||||
int running = 1;
|
||||
while(running)
|
||||
{
|
||||
/* Wait for event */
|
||||
xcb_generic_event_t *event = xcb_wait_for_event(mConnection);
|
||||
if(!event)
|
||||
{
|
||||
std::cout << "i/o error in xcb_wait_for_event" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
switch(event->response_type & ~0x80)
|
||||
{
|
||||
case XCB_KEY_PRESS:
|
||||
/* Quit on key press */
|
||||
std::cout << "got key" << std::endl;
|
||||
running = 0;
|
||||
break;
|
||||
case XCB_KEY_RELEASE:
|
||||
/* Quit on key press */
|
||||
std::cout << "got key" << std::endl;
|
||||
running = 0;
|
||||
break;
|
||||
case XCB_EXPOSE:
|
||||
std::cout << "got expose" << std::endl;
|
||||
/* Handle expose event, draw and swap buffers */
|
||||
mGlxInterface->Draw();
|
||||
mGlxInterface->SwapBuffers(mX11Display);
|
||||
std::cout << "end expose" << std::endl;
|
||||
break;
|
||||
default:
|
||||
std::cout << "got something else" << std::endl;
|
||||
break;
|
||||
}
|
||||
switch(event->response_type & ~0x80)
|
||||
{
|
||||
case XCB_KEY_PRESS:
|
||||
/* Quit on key press */
|
||||
std::cout << "got key" << std::endl;
|
||||
running = 0;
|
||||
break;
|
||||
case XCB_KEY_RELEASE:
|
||||
/* Quit on key press */
|
||||
std::cout << "got key" << std::endl;
|
||||
running = 0;
|
||||
break;
|
||||
case XCB_EXPOSE:
|
||||
std::cout << "got expose" << std::endl;
|
||||
/* Handle expose event, draw and swap buffers */
|
||||
mGlxInterface->Draw();
|
||||
mGlxInterface->SwapBuffers(mX11Display);
|
||||
std::cout << "end expose" << std::endl;
|
||||
break;
|
||||
default:
|
||||
std::cout << "got something else" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
free(event);
|
||||
}
|
||||
mGlxInterface->DestroyWindow(mX11Display);
|
||||
//xcb_destroy_window(mConnection, window);
|
||||
mGlxInterface->DestroyContext(mX11Display);
|
||||
return;
|
||||
free(event);
|
||||
}
|
||||
mGlxInterface->DestroyWindow(mX11Display);
|
||||
//xcb_destroy_window(mConnection, window);
|
||||
mGlxInterface->DestroyContext(mX11Display);
|
||||
return;
|
||||
}
|
||||
|
||||
void XcbInterface::ClearWindow(WindowPtr window)
|
||||
void XcbInterface::ClearWindow(mt::Window* window)
|
||||
{
|
||||
xcb_clear_area(mConnection, 1, mHandles[window], 0, 0,
|
||||
window->GetWidth(), window->GetHeight());
|
||||
xcb_flush(mConnection);
|
||||
if(!window) return;
|
||||
xcb_clear_area(mConnection, 1, mHandles[window], 0, 0,
|
||||
window->GetWidth(), window->GetHeight());
|
||||
xcb_flush(mConnection);
|
||||
}
|
||||
|
||||
void XcbInterface::Loop(DesktopManagerPtr desktopManager)
|
||||
void XcbInterface::Loop(DesktopManager* desktopManager)
|
||||
{
|
||||
if(!mConnection) return;
|
||||
if(!mConnection) return;
|
||||
|
||||
if(mUseOpenGl)
|
||||
{
|
||||
LoopOpenGl(desktopManager);
|
||||
return;
|
||||
}
|
||||
if(mUseOpenGl)
|
||||
{
|
||||
LoopOpenGl(desktopManager);
|
||||
return;
|
||||
}
|
||||
|
||||
xcb_generic_event_t *event;
|
||||
while ((event = xcb_wait_for_event(mConnection)))
|
||||
{
|
||||
switch (event->response_type & ~0x80)
|
||||
{
|
||||
case XCB_EXPOSE:{
|
||||
auto expose_event = reinterpret_cast<xcb_expose_event_t*>(event);
|
||||
xcb_generic_event_t *event;
|
||||
while ((event = xcb_wait_for_event(mConnection)))
|
||||
{
|
||||
switch (event->response_type & ~0x80)
|
||||
{
|
||||
case XCB_EXPOSE:{
|
||||
auto expose_event = reinterpret_cast<xcb_expose_event_t*>(event);
|
||||
|
||||
// Update the window
|
||||
auto window = mWindows[expose_event->window];
|
||||
window->SetSize(expose_event->width, expose_event->height);
|
||||
// Update the window
|
||||
auto window = mWindows[expose_event->window];
|
||||
window->SetSize(expose_event->width, expose_event->height);
|
||||
|
||||
onPaint(desktopManager);
|
||||
/* flush the request */
|
||||
xcb_flush(mConnection);
|
||||
break;
|
||||
}
|
||||
case XCB_KEY_PRESS: {
|
||||
auto kr = reinterpret_cast<xcb_key_press_event_t*>(event);
|
||||
OnKeyPress(kr, desktopManager);
|
||||
break;
|
||||
}
|
||||
onPaint(desktopManager);
|
||||
/* flush the request */
|
||||
xcb_flush(mConnection);
|
||||
break;
|
||||
}
|
||||
case XCB_KEY_PRESS: {
|
||||
auto kr = reinterpret_cast<xcb_key_press_event_t*>(event);
|
||||
OnKeyPress(kr, desktopManager);
|
||||
break;
|
||||
}
|
||||
|
||||
case XCB_KEY_RELEASE: {
|
||||
auto kr = reinterpret_cast<xcb_key_release_event_t*>(event);
|
||||
OnKeyRelease(kr, desktopManager);
|
||||
break;
|
||||
}
|
||||
case XCB_BUTTON_PRESS: {
|
||||
auto press = reinterpret_cast<xcb_button_press_event_t*>(event);
|
||||
OnButtonPress(press, desktopManager);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
/* Unknown event type, ignore it */
|
||||
break;
|
||||
}
|
||||
if(desktopManager->IsModified())
|
||||
{
|
||||
desktopManager->SetIsModified(false);
|
||||
ClearWindow(desktopManager->GetWindowManager()->GetMainWindow());
|
||||
}
|
||||
case XCB_KEY_RELEASE: {
|
||||
auto kr = reinterpret_cast<xcb_key_release_event_t*>(event);
|
||||
OnKeyRelease(kr, desktopManager);
|
||||
break;
|
||||
}
|
||||
case XCB_BUTTON_PRESS: {
|
||||
auto press = reinterpret_cast<xcb_button_press_event_t*>(event);
|
||||
OnButtonPress(press, desktopManager);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
/* Unknown event type, ignore it */
|
||||
break;
|
||||
}
|
||||
if(desktopManager->IsModified())
|
||||
{
|
||||
desktopManager->SetIsModified(false);
|
||||
ClearWindow(desktopManager->GetWindowManager()->GetMainWindow());
|
||||
}
|
||||
|
||||
free (event);
|
||||
}
|
||||
free (event);
|
||||
}
|
||||
}
|
||||
|
||||
void XcbInterface::ShutDown()
|
||||
{
|
||||
if(!mConnection) return;
|
||||
std::cout << "starting shutdown" << std::endl;
|
||||
xcb_disconnect(mConnection);
|
||||
if(mUseOpenGl && mX11Display)
|
||||
{
|
||||
//XCloseDisplay(mX11Display);
|
||||
}
|
||||
std::cout << "ending shutdown" << std::endl;
|
||||
if(!mConnection) return;
|
||||
std::cout << "starting shutdown" << std::endl;
|
||||
xcb_disconnect(mConnection);
|
||||
if(mUseOpenGl && mX11Display)
|
||||
{
|
||||
//XCloseDisplay(mX11Display);
|
||||
}
|
||||
std::cout << "ending shutdown" << std::endl;
|
||||
}
|
||||
|
|
|
@ -23,62 +23,62 @@ class XcbInterface
|
|||
|
||||
private:
|
||||
|
||||
bool mUseOpenGl;
|
||||
std::map<unsigned, WindowPtr> mWindows;
|
||||
std::map<WindowPtr, unsigned> mHandles;
|
||||
unsigned mDefaultWindow;
|
||||
xcb_connection_t* mConnection;
|
||||
xcb_screen_t* mScreen;
|
||||
unsigned mGraphicsContext;
|
||||
_XDisplay* mX11Display;
|
||||
GlxInterfacePtr mGlxInterface;
|
||||
bool mUseOpenGl;
|
||||
std::map<unsigned, mt::Window*> mWindows;
|
||||
std::map<mt::Window*, unsigned> mHandles;
|
||||
unsigned mDefaultWindow;
|
||||
xcb_connection_t* mConnection;
|
||||
xcb_screen_t* mScreen;
|
||||
unsigned mGraphicsContext;
|
||||
_XDisplay* mX11Display;
|
||||
GlxInterfacePtr mGlxInterface;
|
||||
|
||||
public:
|
||||
|
||||
XcbInterface();
|
||||
XcbInterface();
|
||||
|
||||
~XcbInterface();
|
||||
~XcbInterface();
|
||||
|
||||
void SetUseOpenGl(bool use);
|
||||
void onPaint(std::shared_ptr<DesktopManager> desktopManager);
|
||||
void SetUseOpenGl(bool use);
|
||||
void onPaint(DesktopManager* desktopManager);
|
||||
|
||||
void Initialize();
|
||||
void Initialize();
|
||||
|
||||
void InitializeOpenGl();
|
||||
void InitializeOpenGl();
|
||||
|
||||
void CreateOpenGlDrawable(WindowPtr window);
|
||||
void CreateOpenGlDrawable(mt::Window* window);
|
||||
|
||||
void Loop(std::shared_ptr<DesktopManager> desktopManager);
|
||||
void Loop(DesktopManager* desktopManager);
|
||||
|
||||
void LoopOpenGl(std::shared_ptr<DesktopManager> desktopManager);
|
||||
void LoopOpenGl(DesktopManager* desktopManager);
|
||||
|
||||
void ShutDown();
|
||||
void ShutDown();
|
||||
|
||||
void AddWindow(WindowPtr window);
|
||||
void AddWindow(mt::Window* window);
|
||||
|
||||
void ShowWindow(WindowPtr window);
|
||||
void ShowWindow(mt::Window* window);
|
||||
|
||||
void PaintWindow(WindowPtr window);
|
||||
void PaintWindow(mt::Window* window);
|
||||
|
||||
void ClearWindow(WindowPtr window);
|
||||
void ClearWindow(mt::Window* window);
|
||||
|
||||
private:
|
||||
|
||||
void Connect();
|
||||
void Connect();
|
||||
|
||||
void UpdateScreen();
|
||||
void UpdateScreen();
|
||||
|
||||
uint32_t GetEventMask();
|
||||
uint32_t GetEventMask();
|
||||
|
||||
void OnKeyPress(xcb_key_press_event_t* event, DesktopManagerPtr);
|
||||
void OnKeyPress(xcb_key_press_event_t* event, DesktopManager*);
|
||||
|
||||
void OnKeyRelease(xcb_key_press_event_t* event, DesktopManagerPtr);
|
||||
void OnKeyRelease(xcb_key_press_event_t* event, DesktopManager*);
|
||||
|
||||
void OnButtonPress(xcb_button_press_event_t* event, DesktopManagerPtr);
|
||||
void OnButtonPress(xcb_button_press_event_t* event, DesktopManager*);
|
||||
|
||||
void MapWindow(WindowPtr window);
|
||||
void MapWindow(mt::Window* window);
|
||||
|
||||
void CreateGraphicsContext();
|
||||
void CreateGraphicsContext();
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -1,24 +1,25 @@
|
|||
#include "XcbKeyboard.h"
|
||||
|
||||
|
||||
XcbKeyboard::XcbKeyboard()
|
||||
: Keyboard()
|
||||
: Keyboard()
|
||||
{
|
||||
mKeyMap = {{24, "q"}, {25, "w"},
|
||||
{26, "e"}, {27, "r"},
|
||||
{28, "t"}, {29, "y"}, {30, "u"}, {31, "i"}, {32, "o"},
|
||||
{33, "p"}, {38, "a"}, {39, "s"}, {40, "d"}, {41, "f"},
|
||||
{42, "g"}, {43, "h"}, {44, "j"}, {45, "k"}, {46, "l"},
|
||||
{52, "z"}, {53, "x"}, {54, "c"}, {55, "v"}, {56, "b"},
|
||||
{57, "n"}, {58, "m"}};
|
||||
mKeyMap = {{10, "1"}, {11, "2"}, {12, "3"}, {13, "4"}, {14, "5"}, {15, "6"},
|
||||
{16, "7"}, {17, "8"}, {18, "9"}, {19, "0"}, {20, "-"}, {21, "+"}, {22, "KEY_BACK"},
|
||||
{24, "q"}, {25, "w"}, {26, "e"}, {27, "r"}, {28, "t"}, {29, "y"},
|
||||
{30, "u"}, {31, "i"}, {32, "o"}, {33, "p"}, {34, "["}, {35, "]"}, {36, "KEY_RETURN"},
|
||||
{38, "a"}, {39, "s"}, {40, "d"}, {41, "f"}, {42, "g"}, {43, "h"},
|
||||
{44, "j"}, {45, "k"}, {46, "l"}, {47, ":"}, {48, "'"}, {49, "#"},
|
||||
{52, "z"}, {53, "x"}, {54, "c"}, {55, "v"}, {56, "b"},
|
||||
{57, "n"}, {58, "m"}, {59, ","}, {60, "."}, {61, "/"},
|
||||
{65, "KEY_SPACE"}, {66, "KEY_CAPS"}};
|
||||
}
|
||||
|
||||
std::shared_ptr<XcbKeyboard> XcbKeyboard::Create()
|
||||
std::unique_ptr<XcbKeyboard> XcbKeyboard::Create()
|
||||
{
|
||||
return std::make_shared<XcbKeyboard>();
|
||||
return std::make_unique<XcbKeyboard>();
|
||||
}
|
||||
|
||||
std::string XcbKeyboard::GetKeyString(KeyCode keyCode)
|
||||
{
|
||||
return mKeyMap[keyCode];
|
||||
return mKeyMap[keyCode];
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
class XcbKeyboard : public Keyboard
|
||||
{
|
||||
public:
|
||||
XcbKeyboard();
|
||||
XcbKeyboard();
|
||||
|
||||
static std::shared_ptr<XcbKeyboard> Create();
|
||||
static std::unique_ptr<XcbKeyboard> Create();
|
||||
|
||||
std::string GetKeyString(KeyCode keyCode) override;
|
||||
std::string GetKeyString(KeyCode keyCode) override;
|
||||
};
|
||||
|
||||
using XcbKeyboardPtr = std::shared_ptr<XcbKeyboard>;
|
||||
using XcbKeyboardUPtr = std::unique_ptr<XcbKeyboard>;
|
||||
|
|
|
@ -3,48 +3,48 @@
|
|||
#include "RectangleElement.h"
|
||||
#include <memory>
|
||||
|
||||
uint32_t XcbLayerInterface::GetColor(ColorPtr color)
|
||||
uint32_t XcbLayerInterface::GetColor(const Color* color)
|
||||
{
|
||||
return XcbLayerInterface::GetColor(color->GetR(),
|
||||
color->GetG(), color->GetB());
|
||||
return XcbLayerInterface::GetColor(color->GetR(),
|
||||
color->GetG(), color->GetB());
|
||||
}
|
||||
|
||||
uint32_t XcbLayerInterface::GetColor(int r, int g, int b)
|
||||
{
|
||||
return b + (g<<8) + (r<<16);
|
||||
return b + (g<<8) + (r<<16);
|
||||
}
|
||||
|
||||
void XcbLayerInterface::ModifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc,
|
||||
ColorPtr color)
|
||||
const Color* color)
|
||||
{
|
||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
||||
uint32_t values[2] = {XcbLayerInterface::GetColor(color), 0};
|
||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
||||
uint32_t values[2] = {XcbLayerInterface::GetColor(color), 0};
|
||||
|
||||
xcb_change_gc(connection, gc, mask, values);
|
||||
xcb_change_gc(connection, gc, mask, values);
|
||||
}
|
||||
|
||||
void XcbLayerInterface::AddLayer(xcb_connection_t* connection,
|
||||
xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc,
|
||||
VisualLayerPtr layer)
|
||||
xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc,
|
||||
VisualLayer* layer)
|
||||
{
|
||||
if(layer->HasText())
|
||||
{
|
||||
XcbTextInterface::AddTextElement(connection, screen, window, layer->GetText());
|
||||
}
|
||||
else if(layer->HasShape())
|
||||
{
|
||||
auto shape = layer->GetShape();
|
||||
if(shape->GetType() == GeometryElement::Type::Rectangle)
|
||||
{
|
||||
auto rectangle = std::dynamic_pointer_cast<RectangleElement>(shape);
|
||||
Pixel loc = rectangle->GetLocation();
|
||||
auto width = static_cast<uint16_t>(rectangle->GetWidth());
|
||||
auto height = static_cast<uint16_t>(rectangle->GetHeight());
|
||||
xcb_rectangle_t rectangles[] = { { static_cast<int16_t>(loc.GetX()),
|
||||
static_cast<int16_t>(loc.GetY()), width, height} };
|
||||
XcbLayerInterface::ModifyGcColor(connection, gc, rectangle->GetFillColor());
|
||||
xcb_poly_fill_rectangle(connection, window, gc, 1, rectangles);
|
||||
}
|
||||
}
|
||||
if(layer->HasText())
|
||||
{
|
||||
XcbTextInterface::AddTextElement(connection, screen, window, layer->GetText());
|
||||
}
|
||||
else if(layer->HasShape())
|
||||
{
|
||||
auto shape = layer->GetShape();
|
||||
if(shape->GetType() == GeometryElement::Type::Rectangle)
|
||||
{
|
||||
auto rectangle = dynamic_cast<RectangleElement*>(shape);
|
||||
Pixel loc = rectangle->GetLocation();
|
||||
auto width = static_cast<uint16_t>(rectangle->GetWidth());
|
||||
auto height = static_cast<uint16_t>(rectangle->GetHeight());
|
||||
xcb_rectangle_t rectangles[] = { { static_cast<int16_t>(loc.GetX()),
|
||||
static_cast<int16_t>(loc.GetY()), width, height} };
|
||||
XcbLayerInterface::ModifyGcColor(connection, gc, rectangle->GetFillColor());
|
||||
xcb_poly_fill_rectangle(connection, window, gc, 1, rectangles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,15 +8,15 @@ class XcbLayerInterface
|
|||
{
|
||||
public:
|
||||
|
||||
static uint32_t GetColor(ColorPtr);
|
||||
static uint32_t GetColor(const Color* color);
|
||||
|
||||
static uint32_t GetColor(int r, int g, int b);
|
||||
static uint32_t GetColor(int r, int g, int b);
|
||||
|
||||
static void ModifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc,
|
||||
ColorPtr color);
|
||||
static void ModifyGcColor(xcb_connection_t* connection, xcb_gcontext_t gc,
|
||||
const Color* color);
|
||||
|
||||
static void AddLayer(xcb_connection_t* connection,
|
||||
xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc,
|
||||
VisualLayerPtr layer);
|
||||
static void AddLayer(xcb_connection_t* connection,
|
||||
xcb_screen_t* screen, xcb_window_t window, xcb_gcontext_t gc,
|
||||
VisualLayer* layer);
|
||||
};
|
||||
|
||||
|
|
|
@ -2,38 +2,38 @@
|
|||
#include <string.h>
|
||||
|
||||
xcb_gcontext_t XcbTextInterface::GetFontGC(xcb_connection_t *connection,
|
||||
xcb_screen_t *screen, xcb_window_t window, const char*font_name)
|
||||
xcb_screen_t *screen, xcb_window_t window, const char*font_name)
|
||||
{
|
||||
/* get font */
|
||||
xcb_font_t font = xcb_generate_id(connection);
|
||||
xcb_open_font(connection, font, strlen(font_name), font_name);
|
||||
/* get font */
|
||||
xcb_font_t font = xcb_generate_id(connection);
|
||||
xcb_open_font(connection, font, strlen(font_name), font_name);
|
||||
|
||||
/* create graphics context */
|
||||
xcb_gcontext_t gc = xcb_generate_id(connection);
|
||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
|
||||
uint32_t value_list[3] = {screen->black_pixel, screen->white_pixel, font };
|
||||
/* create graphics context */
|
||||
xcb_gcontext_t gc = xcb_generate_id(connection);
|
||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
|
||||
uint32_t value_list[3] = {screen->black_pixel, screen->white_pixel, font };
|
||||
|
||||
xcb_create_gc(connection, gc, window, mask, value_list);
|
||||
xcb_create_gc(connection, gc, window, mask, value_list);
|
||||
|
||||
/* close font */
|
||||
xcb_close_font(connection, font);
|
||||
return gc;
|
||||
/* close font */
|
||||
xcb_close_font(connection, font);
|
||||
return gc;
|
||||
}
|
||||
|
||||
void XcbTextInterface::AddTextElement(xcb_connection_t* connection,
|
||||
xcb_screen_t* screen, xcb_window_t window,
|
||||
TextElementPtr textElement)
|
||||
xcb_screen_t* screen, xcb_window_t window,
|
||||
const TextElement* textElement)
|
||||
{
|
||||
/* get graphics context */
|
||||
xcb_gcontext_t gc = XcbTextInterface::GetFontGC(connection, screen, window,
|
||||
textElement->GetFontLabel().c_str());
|
||||
/* get graphics context */
|
||||
xcb_gcontext_t gc = XcbTextInterface::GetFontGC(connection, screen, window,
|
||||
textElement->GetFontLabel().c_str());
|
||||
|
||||
/* draw the text */
|
||||
std::string content = textElement->GetContent();
|
||||
Pixel loc = textElement->GetLocation();
|
||||
xcb_image_text_8(connection, content.length(), window, gc,
|
||||
loc.GetX(), loc.GetY(), content.c_str());
|
||||
/* draw the text */
|
||||
std::string content = textElement->GetContent();
|
||||
Pixel loc = textElement->GetLocation();
|
||||
xcb_image_text_8(connection, content.length(), window, gc,
|
||||
loc.GetX(), loc.GetY(), content.c_str());
|
||||
|
||||
/* free the gc */
|
||||
xcb_free_gc(connection, gc);
|
||||
/* free the gc */
|
||||
xcb_free_gc(connection, gc);
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
class XcbTextInterface
|
||||
{
|
||||
public:
|
||||
static xcb_gcontext_t GetFontGC(xcb_connection_t* connection,
|
||||
xcb_screen_t*screen, xcb_window_t window, const char*font_name);
|
||||
static xcb_gcontext_t GetFontGC(xcb_connection_t* connection,
|
||||
xcb_screen_t*screen, xcb_window_t window, const char*font_name);
|
||||
|
||||
static void AddTextElement(xcb_connection_t* connection,
|
||||
xcb_screen_t* screen, xcb_window_t window,
|
||||
TextElementPtr textElement);
|
||||
static void AddTextElement(xcb_connection_t* connection,
|
||||
xcb_screen_t* screen, xcb_window_t window,
|
||||
const TextElement* textElement);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue