Implement motif window styles

This commit is contained in:
Phillip Stephens 2015-11-04 23:30:40 -08:00
parent 86491e5585
commit 50075a729a
4 changed files with 105 additions and 15 deletions

View File

@ -86,7 +86,7 @@ enum EModifierKey
MKEY_SHIFT = 1<<3, MKEY_SHIFT = 1<<3,
MKEY_COMMAND = 1<<4 MKEY_COMMAND = 1<<4
}; };
class IWindowCallback class IWindowCallback
{ {
public: public:
@ -119,7 +119,6 @@ public:
virtual void modKeyDown(EModifierKey mod, bool isRepeat) virtual void modKeyDown(EModifierKey mod, bool isRepeat)
{(void)mod;(void)isRepeat;} {(void)mod;(void)isRepeat;}
virtual void modKeyUp(EModifierKey mod) {(void)mod;} virtual void modKeyUp(EModifierKey mod) {(void)mod;}
}; };
enum ETouchType enum ETouchType
@ -129,6 +128,16 @@ enum ETouchType
TOUCH_TRACKPAD = 2 TOUCH_TRACKPAD = 2
}; };
enum EWindowStyle
{
STYLE_NONE = 0,
STYLE_TITLEBAR = 1<<0,
STYLE_RESIZE = 1<<1,
STYLE_CLOSE = 1<<2,
STYLE_DEFAULT = STYLE_TITLEBAR | STYLE_RESIZE | STYLE_CLOSE
};
class IWindow class IWindow
{ {
public: public:
@ -172,6 +181,8 @@ public:
virtual IGraphicsCommandQueue* getCommandQueue()=0; virtual IGraphicsCommandQueue* getCommandQueue()=0;
virtual IGraphicsDataFactory* getDataFactory()=0; virtual IGraphicsDataFactory* getDataFactory()=0;
virtual void setStyle(EWindowStyle style)=0;
virtual EWindowStyle getStyle() const=0;
/* Creates a new context on current thread!! Call from client loading thread */ /* Creates a new context on current thread!! Call from client loading thread */
virtual IGraphicsDataFactory* getLoadContextDataFactory()=0; virtual IGraphicsDataFactory* getLoadContextDataFactory()=0;

View File

@ -115,7 +115,7 @@ struct WindowWayland : IWindow
std::string getTitle() std::string getTitle()
{ {
return "";
} }
void setTitle(const std::string& title) void setTitle(const std::string& title)
@ -150,12 +150,20 @@ struct WindowWayland : IWindow
float getVirtualPixelFactor() const float getVirtualPixelFactor() const
{ {
return 0;
} }
void setStyle(EWindowStyle /*style*/)
{}
EWindowStyle getStyle() const
{
return STYLE_NONE;
}
bool isFullscreen() const bool isFullscreen() const
{ {
return false;
} }
void setFullscreen(bool fs) void setFullscreen(bool fs)
@ -169,12 +177,12 @@ struct WindowWayland : IWindow
uintptr_t getPlatformHandle() const uintptr_t getPlatformHandle() const
{ {
return 0;
} }
ETouchType getTouchType() const ETouchType getTouchType() const
{ {
return TOUCH_NONE;
} }

View File

@ -18,11 +18,27 @@
#include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon.h>
#include <X11/extensions/XInput2.h> #include <X11/extensions/XInput2.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <LogVisor/LogVisor.hpp>
#define REF_DPMM 3.7824 /* 96 DPI */ #define REF_DPMM 3.7824 /* 96 DPI */
#define FS_ATOM "_NET_WM_STATE_FULLSCREEN" #define FS_ATOM "_NET_WM_STATE_FULLSCREEN"
#include <LogVisor/LogVisor.hpp> #define MWM_HINTS_FUNCTIONS (1L << 0)
#define MWM_HINTS_DECORATIONS (1L << 1)
#define MWM_DECOR_BORDER (1L<<1)
#define MWM_DECOR_RESIZEH (1L<<2)
#define MWM_DECOR_TITLE (1L<<3)
#define MWM_DECOR_MENU (1L<<4)
#define MWM_DECOR_MINIMIZE (1L<<5)
#define MWM_DECOR_MAXIMIZE (1L<<6)
#define MWM_FUNC_RESIZE (1L<<1)
#define MWM_FUNC_MOVE (1L<<2)
#define MWM_FUNC_MINIMIZE (1L<<3)
#define MWM_FUNC_MAXIMIZE (1L<<4)
#define MWM_FUNC_CLOSE (1L<<5)
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
@ -391,6 +407,9 @@ class WindowXlib : public IWindow
float m_pixelFactor; float m_pixelFactor;
bool m_inFs = false; bool m_inFs = false;
/* Cached window style */
EWindowStyle m_styleFlags;
public: public:
WindowXlib(const std::string& title, WindowXlib(const std::string& title,
@ -474,6 +493,8 @@ public:
XMapWindow(m_xDisp, m_windowId); XMapWindow(m_xDisp, m_windowId);
XFlush(m_xDisp); XFlush(m_xDisp);
setStyle(STYLE_DEFAULT);
m_gfxCtx.initializeContext(); m_gfxCtx.initializeContext();
} }
@ -574,13 +595,14 @@ public:
bool isFullscreen() const bool isFullscreen() const
{ {
return m_inFs;
unsigned long nitems; unsigned long nitems;
Atom actualType; Atom actualType;
int actualFormat; int actualFormat;
unsigned long bytes; unsigned long bytes;
Atom* vals = nullptr; Atom* vals = nullptr;
bool fullscreen = false; bool fullscreen = false;
if (XGetWindowProperty(m_xDisp, m_windowId, XInternAtom(m_xDisp, "_NET_WM_STATE", True), 0, ~0l, False, if (XGetWindowProperty(m_xDisp, m_windowId, S_ATOMS->m_netwmState, 0, ~0l, False,
XA_ATOM, &actualType, &actualFormat, &nitems, &bytes, (unsigned char**)&vals) == Success) XA_ATOM, &actualType, &actualFormat, &nitems, &bytes, (unsigned char**)&vals) == Success)
{ {
for (int i=0 ; i<nitems ; ++i) for (int i=0 ; i<nitems ; ++i)
@ -597,7 +619,46 @@ public:
return false; return false;
} }
void setStyle(EWindowStyle style)
{
struct
{
unsigned long flags;
unsigned long functions;
unsigned long decorations;
long inputMode;
unsigned long status;
} wmHints = {0};
if (S_ATOMS->m_motifWmHints)
{
wmHints.flags = MWM_HINTS_DECORATIONS | MWM_HINTS_FUNCTIONS;
if (style & STYLE_TITLEBAR)
{
wmHints.decorations |= MWM_DECOR_BORDER | MWM_DECOR_TITLE | MWM_DECOR_MINIMIZE | MWM_DECOR_MENU;
wmHints.functions |= MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE;
}
if (style & STYLE_RESIZE)
{
wmHints.decorations |= MWM_DECOR_MAXIMIZE | MWM_DECOR_RESIZEH;
wmHints.functions |= MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE;
}
if (style & STYLE_CLOSE)
wmHints.functions |= MWM_FUNC_CLOSE;
XChangeProperty(m_xDisp, m_windowId, S_ATOMS->m_motifWmHints, S_ATOMS->m_motifWmHints, 32, PropModeReplace, (unsigned char*)&wmHints, 5);
}
m_styleFlags = style;
}
EWindowStyle getStyle() const
{
return m_styleFlags;
}
void setFullscreen(bool fs) void setFullscreen(bool fs)
{ {
if (fs == m_inFs) if (fs == m_inFs)
@ -605,14 +666,17 @@ public:
XEvent fsEvent = {0}; XEvent fsEvent = {0};
fsEvent.xclient.type = ClientMessage; fsEvent.xclient.type = ClientMessage;
fsEvent.xclient.serial = 0;
fsEvent.xclient.send_event = True;
fsEvent.xclient.window = m_windowId; fsEvent.xclient.window = m_windowId;
fsEvent.xclient.message_type = XInternAtom(m_xDisp, "_NET_WM_STATE", False); fsEvent.xclient.message_type = S_ATOMS->m_netwmState;
fsEvent.xclient.format = 32; fsEvent.xclient.format = 32;
fsEvent.xclient.data.l[0] = fs; fsEvent.xclient.data.l[0] = fs;
fsEvent.xclient.data.l[1] = XInternAtom(m_xDisp, "_NET_WM_STATE_FULLSCREEN", False); fsEvent.xclient.data.l[1] = S_ATOMS->m_netwmStateFullscreen;
fsEvent.xclient.data.l[2] = 0; fsEvent.xclient.data.l[2] = 0;
XSendEvent(m_xDisp, DefaultRootWindow(m_xDisp), False, XSendEvent(m_xDisp, DefaultRootWindow(m_xDisp), False,
StructureNotifyMask | SubstructureRedirectMask, (XEvent*)&fsEvent); StructureNotifyMask | SubstructureRedirectMask, (XEvent*)&fsEvent);
m_inFs = fs; m_inFs = fs;
} }
@ -1014,7 +1078,6 @@ public:
return m_gfxCtx.getLoadContextDataFactory(); return m_gfxCtx.getLoadContextDataFactory();
} }
bool _isWindowMapped() bool _isWindowMapped()
{ {
XWindowAttributes attr; XWindowAttributes attr;

View File

@ -125,6 +125,7 @@ public:
struct CTestWindowCallback : IWindowCallback struct CTestWindowCallback : IWindowCallback
{ {
bool m_fullscreenToggleRequested = false;
SWindowRect m_lastRect; SWindowRect m_lastRect;
bool m_rectDirty = false; bool m_rectDirty = false;
@ -149,7 +150,7 @@ struct CTestWindowCallback : IWindowCallback
} }
void scroll(const SWindowCoord& coord, const SScrollDelta& scroll) void scroll(const SWindowCoord& coord, const SScrollDelta& scroll)
{ {
fprintf(stderr, "Mouse Scroll (%f,%f) (%f,%f)\n", coord.norm[0], coord.norm[1], scroll.delta[0], scroll.delta[1]); //fprintf(stderr, "Mouse Scroll (%f,%f) (%f,%f)\n", coord.norm[0], coord.norm[1], scroll.delta[0], scroll.delta[1]);
} }
void touchDown(const STouchCoord& coord, uintptr_t tid) void touchDown(const STouchCoord& coord, uintptr_t tid)
@ -175,7 +176,8 @@ struct CTestWindowCallback : IWindowCallback
} }
void specialKeyDown(ESpecialKey key, EModifierKey mods, bool isRepeat) void specialKeyDown(ESpecialKey key, EModifierKey mods, bool isRepeat)
{ {
if (key == boo::KEY_ENTER && (mods & boo::MKEY_ALT))
m_fullscreenToggleRequested = true;
} }
void specialKeyUp(ESpecialKey key, EModifierKey mods) void specialKeyUp(ESpecialKey key, EModifierKey mods)
{ {
@ -373,6 +375,12 @@ struct TestApplicationCallback : IApplicationCallback
windowCallback.m_rectDirty = false; windowCallback.m_rectDirty = false;
} }
if (windowCallback.m_fullscreenToggleRequested)
{
mainWindow->setFullscreen(!mainWindow->isFullscreen());
windowCallback.m_fullscreenToggleRequested = false;
}
gfxQ->setRenderTarget(m_renderTarget); gfxQ->setRenderTarget(m_renderTarget);
SWindowRect r = windowCallback.m_lastRect; SWindowRect r = windowCallback.m_lastRect;
r.location[0] = 0; r.location[0] = 0;