Skip to content

Commit

Permalink
First pass of plClientWindow work
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Nov 24, 2023
1 parent 8dd520c commit 638d651
Show file tree
Hide file tree
Showing 15 changed files with 696 additions and 256 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ jobs:
libcairo2 \
libsecret-1-dev \
libtool \
libx11-xcb-dev \
libxcb-keysyms1-dev \
libxcb-xfixes0-dev \
libx11-dev \
libxfixes-dev \
nasm \
ninja-build \
qtbase5-dev
Expand Down
21 changes: 10 additions & 11 deletions Sources/Plasma/Apps/plClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ set(plClient_HEADERS
plClientCreatable.h
plClientLoader.h
plClientUpdateFormat.h
plClientWindow.h
)

set(plClient_SOURCES
Expand All @@ -76,8 +77,12 @@ set(plClient_TEXT
)

if(WIN32)
list(APPEND plClient_HEADERS
win32/plWin32ClientWindow.h
)
list(APPEND plClient_SOURCES
win32/plClient_Win.cpp
win32/plWin32ClientWindow.cpp
win32/winmain.cpp
)
list(APPEND plClient_RESOURCES
Expand Down Expand Up @@ -118,7 +123,12 @@ elseif(APPLE)
Mac-Cocoa/PLSPatcherWindowController.xib
)
elseif(UNIX AND NOT APPLE)
list(APPEND plClient_HEADERS
linux/plX11ClientWindow.h
)

list(APPEND plClient_SOURCES
linux/plX11ClientWindow.cpp
linux/main.cpp
)
else()
Expand Down Expand Up @@ -239,17 +249,6 @@ target_link_libraries(
)
target_include_directories(plClient PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")

if(UNIX AND NOT APPLE)
target_link_libraries(
plClient
PRIVATE
xcb
xcb-xfixes
xcb-keysyms
X11
)
endif()

if(PLASMA_EXTERNAL_RELEASE)
set_target_properties(plClient PROPERTIES OUTPUT_NAME "UruExplorer")
endif(PLASMA_EXTERNAL_RELEASE)
Expand Down
8 changes: 4 additions & 4 deletions Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
// Plasma engine
#include "plClient/plClient.h"
#include "plClient/plClientLoader.h"
#include "plClient/plClientWindow.h"
#include "plCmdParser.h"
#include "pfConsoleCore/pfConsoleEngine.h"
#include "pfGameGUIMgr/pfGameGUIMgr.h"
Expand Down Expand Up @@ -120,7 +121,6 @@ @interface AppDelegate : NSWindowController <NSApplicationDelegate,
}
void plClient::IChangeResolution(int width, int height) {}
void plClient::IUpdateProgressIndicator(plOperationProgress* progress) {}
void plClient::ShowClientWindow() {}
void plClient::FlashWindow()
{
dispatch_async(dispatch_get_main_queue(), ^{
Expand Down Expand Up @@ -200,7 +200,6 @@ - (void)startRunLoop
if (cmdParser.IsSpecified(kArgSkipIntroMovies))
gClient->SetFlag(plClient::kFlagSkipIntroMovies);
gClient->WindowActivate(TRUE);
gClient->SetMessagePumpProc(PumpMessageQueueProc);
gClient.Start();
});

Expand Down Expand Up @@ -451,8 +450,9 @@ - (void)startClient
[self.window makeKeyAndOrderFront:self];
self.renderLayer = self.window.contentView.layer;

gClient.SetClientWindow((hsWindowHndl)(__bridge void*)self.window);
gClient.SetClientDisplay((hsWindowHndl)NULL);
plStubClientWindow* cwnd = new plStubClientWindow((hsWindowHndl)(__bridge void*)self.window, (hsWindowHndl)nullptr);
cwnd->SetMessagePumpProc(PumpMessageQueueProc);
gClient.SetClientWindow(cwnd);

if (!gClient) {
exit(0);
Expand Down
138 changes: 26 additions & 112 deletions Sources/Plasma/Apps/plClient/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include <regex>
#include <termios.h>
#include <unistd.h>
#include <xcb/xcb.h>
#include <xcb/xcb_keysyms.h>
#include <xcb/xfixes.h>
#include <xcb/xproto.h>
#include <X11/Xlib-xcb.h>

// Undefine the problematic X11 stuff
#undef Status

#include "HeadSpin.h"
#include "plCmdParser.h"
Expand All @@ -66,6 +58,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include "plClient.h"
#include "plClientLoader.h"
#include "plX11ClientWindow.h"

#include "pnEncryption/plChallengeHash.h"

Expand All @@ -88,10 +81,11 @@ extern bool gPythonLocal;
extern bool gSDLLocal;

static plClientLoader gClient;
static xcb_connection_t* gXConn;
static xcb_key_symbols_t* keysyms;
static pcSmallRect gWindowSize;
static bool gHasXFixes = false;
static plClientWindow* gWindow = nullptr;
//static xcb_connection_t* gXConn;
//static xcb_key_symbols_t* keysyms;
//static pcSmallRect gWindowSize;
//static bool gHasXFixes = false;
static hsSemaphore statusFlag;

enum
Expand Down Expand Up @@ -165,24 +159,19 @@ void plClient::IResizeNativeDisplayDevice(int width, int height, bool windowed)
{
hsStatusMessage(ST::format("Setting window size to {}×{}", width, height).c_str());

#if 0
const uint32_t values[] = { uint32_t(width), uint32_t(height) };
xcb_configure_window(gXConn, (xcb_window_t)(uintptr_t)fWindowHndl,
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
values);

gWindowSize.fWidth = width;
gWindowSize.fHeight = height;
#endif
}

void plClient::IChangeResolution(int width, int height) {}
void plClient::IUpdateProgressIndicator(plOperationProgress* progress) {}

void plClient::ShowClientWindow() {
/* Map the window on the screen */
xcb_map_window(gXConn, (xcb_window_t)(uintptr_t)fWindowHndl);
xcb_flush(gXConn);
}

void plClient::FlashWindow() {}


Expand Down Expand Up @@ -372,77 +361,6 @@ static uint32_t ParseRendererArgument(const ST::string& requested)
return hsG3DDeviceSelector::kDevTypeUnknown;
}

static bool XInit(xcb_connection_t* connection)
{
gWindowSize.Set(0, 0, 800, 600);

/* Get the X11 key mappings */
keysyms = xcb_key_symbols_alloc(connection);

/* Get the first screen */
const xcb_setup_t* setup = xcb_get_setup(connection);
xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup);
xcb_screen_t* screen = iter.data;

/* Check for XFixes support for hiding the cursor */
const xcb_query_extension_reply_t* qe_reply = xcb_get_extension_data(gXConn, &xcb_xfixes_id);
if (qe_reply && qe_reply->present)
{
/* We *must* negotiate the XFixes version with the server */
xcb_xfixes_query_version_cookie_t qv_cookie = xcb_xfixes_query_version(gXConn, XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION);
xcb_xfixes_query_version_reply_t* qv_reply = xcb_xfixes_query_version_reply(gXConn, qv_cookie, nullptr);

//#ifndef HS_DEBUGGING // Don't hide the cursor when debugging
gHasXFixes = qv_reply->major_version >= 4;
//#endif

free(qv_reply);
}

const uint32_t event_mask = XCB_EVENT_MASK_EXPOSURE
| XCB_EVENT_MASK_KEY_PRESS
| XCB_EVENT_MASK_KEY_RELEASE
| XCB_EVENT_MASK_POINTER_MOTION
| XCB_EVENT_MASK_BUTTON_PRESS
| XCB_EVENT_MASK_BUTTON_RELEASE
| XCB_EVENT_MASK_ENTER_WINDOW
| XCB_EVENT_MASK_LEAVE_WINDOW
| XCB_EVENT_MASK_STRUCTURE_NOTIFY;

/* Create the window */
xcb_window_t window = xcb_generate_id(connection);
xcb_create_window(connection, /* Connection */
XCB_COPY_FROM_PARENT, /* depth (same as root)*/
window, /* window Id */
screen->root, /* parent window */
/* x, y */
gWindowSize.fX, gWindowSize.fY,
/* width, height */
gWindowSize.fWidth, gWindowSize.fHeight,
10, /* border_width */
XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
screen->root_visual, /* visual */
XCB_CW_EVENT_MASK, /* masks */
&event_mask); /* masks */

const char* title = ST::format("{}", plProduct::LongName()).c_str();
xcb_change_property(connection,
XCB_PROP_MODE_REPLACE,
window,
XCB_ATOM_WM_NAME,
XCB_ATOM_STRING,
8,
strlen(title),
title);

Display* display = XOpenDisplay(nullptr);

gClient.SetClientWindow((hsWindowHndl)(uintptr_t)window);
gClient.SetClientDisplay((hsWindowHndl)display);
gClient.Init();
return true;
}

static void PumpMessageQueueProc()
{
static const unsigned char KEYCODE_LINUX_TO_HID[256] = {
Expand All @@ -457,6 +375,7 @@ static void PumpMessageQueueProc()
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};

#if 0
xcb_generic_event_t* event;
while ((event = xcb_poll_for_event(gXConn))) {
switch (event->response_type & ~0x80)
Expand Down Expand Up @@ -643,9 +562,9 @@ static void PumpMessageQueueProc()

free(event);
}
#endif
}

// Stub main function so it compiles on non-Windows
int main(int argc, const char** argv)
{
PF_CONSOLE_INIT_ALL();
Expand Down Expand Up @@ -689,6 +608,12 @@ int main(int argc, const char** argv)
if (cmdParser.IsSpecified(kArgServerIni))
serverIni = cmdParser.GetString(kArgServerIni);

gWindow = new plX11ClientWindow();
if (!gWindow->PreInit()) {
hsMessageBox(ST_LITERAL("Failed to initialize plClient"), ST_LITERAL("Error"), hsMessageBoxNormal);
return 1;
}

// Load an optional general.ini
plFileName gipath = plFileName::Join(plFileSystem::GetInitPath(), "general.ini");
FILE *generalini = plFileSystem::Open(gipath, "rb");
Expand All @@ -712,22 +637,17 @@ int main(int argc, const char** argv)
}
else
{
hsMessageBox("No server.ini file found. Please check your URU installation.", "Error", hsMessageBoxNormal);
hsMessageBox(ST_LITERAL("No server.ini file found. Please check your URU installation."), ST_LITERAL("Error"), hsMessageBoxNormal);
return 1;
}

if (!XInitThreads()) {
hsMessageBox("Failed to initialize plClient", "Error", hsMessageBoxNormal);
if (!gWindow->CreateClientWindow()) {
hsMessageBox(ST_LITERAL("Failed to initialize plClient"), ST_LITERAL("Error"), hsMessageBoxNormal);
return 1;
}

/* Open the connection to the X server */
gXConn = xcb_connect(nullptr, nullptr);

if (!XInit(gXConn)) {
hsMessageBox("Failed to initialize plClient", "Error", hsMessageBoxNormal);
return 1;
}
gClient.SetClientWindow(gWindow);
gClient.Init();

NetCliAuthAutoReconnectEnable(false);
NetCommStartup();
Expand All @@ -740,8 +660,6 @@ int main(int argc, const char** argv)
gClient.ShutdownEnd();
NetCommShutdown();

xcb_disconnect(gXConn);

return 0;
}

Expand All @@ -763,24 +681,20 @@ int main(int argc, const char** argv)
if (cmdParser.IsSpecified(kArgSkipIntroMovies))
gClient->SetFlag(plClient::kFlagSkipIntroMovies);

gClient->SetMessagePumpProc(PumpMessageQueueProc);
gClient.Start();

do {
gClient->MainLoop();
if (gClient->GetDone()) {
while (true) {
bool isDone = gClient->MainLoop();

if (isDone) {
gClient.ShutdownStart();
break;
}

PumpMessageQueueProc();
} while (true);
}
}

gClient.ShutdownEnd();
NetCommShutdown();

xcb_disconnect(gXConn);

return 0;
}
Loading

0 comments on commit 638d651

Please sign in to comment.