forked from Mirrors/openclonk
138 lines
3.9 KiB
C++
138 lines
3.9 KiB
C++
/*
|
|
* OpenClonk, http://www.openclonk.org
|
|
*
|
|
* Copyright (c) 2005-2009, RedWolf Design GmbH, http://www.clonk.de
|
|
*
|
|
* Portions might be copyrighted by other authors who have contributed
|
|
* to OpenClonk.
|
|
*
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
* See isc_license.txt for full license and disclaimer.
|
|
*
|
|
* "Clonk" is a registered trademark of Matthes Bender.
|
|
* See clonk_trademark_license.txt for full license.
|
|
*/
|
|
#ifndef INC_STD_X_PRIVATE_H
|
|
#define INC_STD_X_PRIVATE_H
|
|
|
|
class CX11Proc: public StdSchedulerProc {
|
|
|
|
public:
|
|
CX11Proc(CStdApp *pApp): pApp(pApp) { }
|
|
~CX11Proc() { }
|
|
|
|
CStdApp *pApp;
|
|
|
|
// StdSchedulerProc override
|
|
virtual void GetFDs(std::vector<struct pollfd> & fds) {
|
|
pollfd pfd = { XConnectionNumber(pApp->dpy), POLLIN, 0 };
|
|
fds.push_back(pfd);
|
|
}
|
|
virtual bool Execute(int iTimeout = -1, pollfd * readyfds = 0) {
|
|
pApp->OnXInput();
|
|
return true;
|
|
}
|
|
};
|
|
|
|
#ifdef WITH_GLIB
|
|
class CGLibProc: public StdSchedulerProc
|
|
{
|
|
public:
|
|
CGLibProc(GMainContext *context): context(context), query_time(-1) { fds.resize(1); g_main_context_ref(context); }
|
|
~CGLibProc() { g_main_context_unref(context); }
|
|
|
|
GMainContext *context;
|
|
std::vector<pollfd> fds;
|
|
int query_time;
|
|
int timeout;
|
|
int max_priority;
|
|
|
|
void query()
|
|
{
|
|
// If Execute() has not yet been called, then finish the current iteration first.
|
|
// Note that we cannot simply ignore the query() call, as new
|
|
// FDs or Timeouts may have been added to the Glib loop in the meanwhile
|
|
if (query_time >= 0)
|
|
g_main_context_check(context, max_priority, (GPollFD*) &fds[0], fds.size());
|
|
|
|
g_main_context_prepare (context, &max_priority);
|
|
unsigned int fd_count;
|
|
if(fds.empty()) fds.resize(1);
|
|
while ((fd_count = g_main_context_query(context, max_priority, &timeout, (GPollFD*) &fds[0], fds.size())) > fds.size())
|
|
{
|
|
fds.resize(fd_count);
|
|
}
|
|
// Make sure we don't report more FDs than there are available
|
|
fds.resize(fd_count);
|
|
query_time = timeGetTime();
|
|
}
|
|
// StdSchedulerProc override
|
|
virtual void GetFDs(std::vector<struct pollfd> & rfds)
|
|
{
|
|
query();
|
|
rfds.insert(rfds.end(), fds.begin(), fds.end());
|
|
}
|
|
virtual int GetNextTick(int Now)
|
|
{
|
|
query();
|
|
if(timeout < 0) return timeout;
|
|
return query_time + timeout;
|
|
}
|
|
virtual bool Execute(int iTimeout = -1, pollfd * readyfds = 0) {
|
|
if (query_time < 0) return true;
|
|
g_main_context_check(context, max_priority, readyfds ? (GPollFD*) readyfds : (GPollFD*) &fds[0], fds.size());
|
|
g_main_context_dispatch(context);
|
|
query_time = -1;
|
|
return true;
|
|
}
|
|
};
|
|
#endif // WITH_GLIB
|
|
|
|
class CStdAppPrivate {
|
|
public:
|
|
#ifdef WITH_GLIB
|
|
CGLibProc GLibProc;
|
|
#endif
|
|
|
|
CStdAppPrivate(CStdApp *pApp):
|
|
#ifdef USE_X11
|
|
PrimarySelection(), ClipboardSelection(),
|
|
LastEventTime(CurrentTime), tasked_out(false), pending_desktop(false),
|
|
xim(0), xic(0), X11Proc(pApp),
|
|
#endif
|
|
#ifdef WITH_GLIB
|
|
GLibProc(g_main_context_default()),
|
|
#endif // WITH_GLIB
|
|
argc(0), argv(0) { }
|
|
static CStdWindow * GetWindow(unsigned long wnd);
|
|
static void SetWindow(unsigned long wnd, CStdWindow * pWindow);
|
|
#ifdef USE_X11
|
|
bool SwitchToFullscreen(CStdApp * pApp, Window wnd);
|
|
void SwitchToDesktop(CStdApp * pApp, Window wnd);
|
|
void SetEWMHFullscreen (CStdApp * pApp, bool fFullScreen, Window wnd);
|
|
struct ClipboardData {
|
|
StdStrBuf Text;
|
|
unsigned long AcquirationTime;
|
|
} PrimarySelection, ClipboardSelection;
|
|
unsigned long LastEventTime;
|
|
typedef std::map<unsigned long, CStdWindow *> WindowListT;
|
|
static WindowListT WindowList;
|
|
XF86VidModeModeInfo xf86vmode_oldmode, xf86vmode_targetmode;
|
|
int xrandr_oldmode;
|
|
unsigned short xrandr_rot;
|
|
int xrandr_event;
|
|
bool tasked_out; int wdt; int hgt;
|
|
bool pending_desktop;
|
|
static const int PENDING_DESKTOP_DELAY = 3;
|
|
XIM xim;
|
|
XIC xic;
|
|
Bool detectable_autorepeat_supported;
|
|
CX11Proc X11Proc;
|
|
#endif
|
|
int argc; char ** argv;
|
|
};
|
|
|
|
#endif // INC_STD_X_PRIVATE_H
|