[client] x11/sdl: get the border dimensions from the backend

This commit is contained in:
Geoffrey McRae 2021-01-25 22:23:53 +11:00
parent 6b1e310343
commit dbb18a6ecb
6 changed files with 98 additions and 19 deletions

View file

@ -23,6 +23,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include "app.h"
#include "kb.h"
#include "common/types.h"
#include "common/debug.h"
struct SDLDSState
@ -146,8 +147,20 @@ static bool sdlEventFilter(SDL_Event * event)
case SDL_WINDOWEVENT_SIZE_CHANGED:
case SDL_WINDOWEVENT_RESIZED:
app_handleResizeEvent(event->window.data1, event->window.data2);
{
struct Border border;
SDL_GetWindowBordersSize(
app_getWindow(),
&border.top,
&border.left,
&border.bottom,
&border.right
);
app_handleResizeEvent(event->window.data1, event->window.data2,
border);
return true;
}
case SDL_WINDOWEVENT_MOVED:
app_updateWindowPos(event->window.data1, event->window.data2);

View file

@ -46,6 +46,11 @@ struct X11DSState
bool keyboardGrabbed;
bool entered;
bool focused;
struct Rect rect;
struct Border border;
Atom aNetReqFrameExtents;
Atom aNetFrameExtents;
// clipboard members
Atom aSelection;
@ -93,6 +98,25 @@ static bool x11Init(SDL_SysWMinfo * info)
x11.display = info->info.x11.display;
x11.window = info->info.x11.window;
x11.aNetReqFrameExtents =
XInternAtom(x11.display, "_NET_REQUEST_FRAME_EXTENTS", True);
x11.aNetFrameExtents =
XInternAtom(x11.display, "_NET_FRAME_EXTENTS", True);
if (x11.aNetReqFrameExtents)
{
XEvent reqevent =
{
.type = ClientMessage,
.xclient.window = x11.window,
.xclient.format = 32,
.xclient.message_type = x11.aNetReqFrameExtents
};
XSendEvent(x11.display, DefaultRootWindow(x11.display), False,
SubstructureNotifyMask | SubstructureRedirectMask, &reqevent);
}
int major = 2;
int minor = 3;
if (XIQueryVersion(x11.display, &major, &minor) != Success)
@ -318,8 +342,13 @@ static bool x11EventFilter(SDL_Event * event)
&y,
&child);
x11.rect.x = x;
x11.rect.y = y;
x11.rect.w = xe.xconfigure.width;
x11.rect.h = xe.xconfigure.height;
app_updateWindowPos(x, y);
app_handleResizeEvent(xe.xconfigure.width, xe.xconfigure.height);
app_handleResizeEvent(x11.rect.w, x11.rect.h, x11.border);
return true;
}
@ -558,14 +587,45 @@ static bool x11EventFilter(SDL_Event * event)
return true;
case PropertyNotify:
if (xe.xproperty.display != x11.display ||
xe.xproperty.window != x11.window ||
xe.xproperty.atom != x11.aSelData ||
xe.xproperty.state != PropertyNewValue ||
x11.lowerBound == 0)
if (xe.xproperty.display != x11.display ||
xe.xproperty.window != x11.window ||
xe.xproperty.state != PropertyNewValue)
return false;
x11CBSelectionIncr(xe.xproperty);
if (xe.xproperty.atom == x11.aNetFrameExtents)
{
Atom type;
int fmt;
unsigned long num, bytes;
unsigned char *data;
if (XGetWindowProperty(x11.display, x11.window,
x11.aNetFrameExtents, 0, 4, False, AnyPropertyType,
&type, &fmt, &num, &bytes, &data) != Success)
return true;
if (num >= 4)
{
long *cardinal = (long *)data;
x11.border.left = cardinal[0];
x11.border.right = cardinal[1];
x11.border.top = cardinal[2];
x11.border.bottom = cardinal[3];
app_handleResizeEvent(x11.rect.w, x11.rect.h, x11.border);
}
XFree(data);
return true;
}
if (xe.xproperty.atom == x11.aSelData)
{
if (x11.lowerBound == 0)
return false;
x11CBSelectionIncr(xe.xproperty);
return true;
}
return true;
default:

View file

@ -19,6 +19,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <stdbool.h>
#include "common/types.h"
#include "interface/displayserver.h"
SDL_Window * app_getWindow(void);
@ -30,7 +31,7 @@ bool app_cursorWantsRaw(void);
bool app_cursorInWindow(void);
void app_updateCursorPos(double x, double y);
void app_updateWindowPos(int x, int y);
void app_handleResizeEvent(int w, int h);
void app_handleResizeEvent(int w, int h, const struct Border border);
void app_handleMouseGrabbed(double ex, double ey);
void app_handleMouseNormal(double ex, double ey);
void app_handleMouseBasic(void);

View file

@ -458,8 +458,8 @@ void app_handleMouseNormal(double ex, double ey)
const int ty = (local.y <= 0.0) ? floor(local.y) : ceil(local.y);
if (core_isValidPointerPos(
g_state.windowPos.x + g_state.border.x + tx,
g_state.windowPos.y + g_state.border.y + ty))
g_state.windowPos.x + g_state.border.left + tx,
g_state.windowPos.y + g_state.border.top + ty))
{
core_setCursorInView(false);
@ -570,14 +570,9 @@ void app_updateWindowPos(int x, int y)
g_state.windowPos.y = y;
}
void app_handleResizeEvent(int w, int h)
void app_handleResizeEvent(int w, int h, const struct Border border)
{
SDL_GetWindowBordersSize(g_state.window,
&g_state.border.y,
&g_state.border.x,
&g_state.border.h,
&g_state.border.w
);
memcpy(&g_state.border, &border, sizeof(border));
/* don't do anything else if the window dimensions have not changed */
if (g_state.windowW == w && g_state.windowH == h)

View file

@ -58,7 +58,7 @@ struct AppState
int windowCX, windowCY;
LG_RendererRotate rotate;
bool focused;
SDL_Rect border;
struct Border border;
SDL_Point srcSize;
LG_RendererRect dstRect;
bool posInfoValid;

View file

@ -25,6 +25,16 @@ struct DoublePoint
double x, y;
};
struct Rect
{
int x, y, w, h;
};
struct Border
{
int left, top, right, bottom;
};
typedef enum FrameType
{
FRAME_TYPE_INVALID ,