Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-05-29 06:23:19 +0300
committerCampbell Barton <campbell@blender.org>2022-05-29 06:25:58 +0300
commit93e4b15767cf958d5a07ba6acce25438f244bf22 (patch)
tree3e00d28afcf4f4e2b2c952458feb9ac0b1350553 /intern/ghost/intern/GHOST_WindowX11.cpp
parent13373a6ccd5e44d14cd57374820b895bbd0898f3 (diff)
Cleanup: clang-tidy for GHOST X11/SDL/Wayland/NULL backends
Also early exit in some functions.
Diffstat (limited to 'intern/ghost/intern/GHOST_WindowX11.cpp')
-rw-r--r--intern/ghost/intern/GHOST_WindowX11.cpp180
1 files changed, 107 insertions, 73 deletions
diff --git a/intern/ghost/intern/GHOST_WindowX11.cpp b/intern/ghost/intern/GHOST_WindowX11.cpp
index e2d23ceac0b..3569c9574f1 100644
--- a/intern/ghost/intern/GHOST_WindowX11.cpp
+++ b/intern/ghost/intern/GHOST_WindowX11.cpp
@@ -44,19 +44,19 @@
#include <unistd.h>
#include <algorithm>
-#include <limits.h>
-#include <math.h>
+#include <climits>
+#include <cmath>
#include <string>
/* For obscure full screen mode stuff
* lifted verbatim from blut. */
-typedef struct {
+using MotifWmHints = struct {
long flags;
long functions;
long decorations;
long input_mode;
-} MotifWmHints;
+};
enum {
MWM_HINTS_FUNCTIONS = (1L << 0),
@@ -107,7 +107,7 @@ static XVisualInfo *x11_visualinfo_from_glx(Display *display,
int glx_major, glx_minor, glx_version; /* GLX version: major.minor */
int glx_attribs[64];
- *fbconfig = NULL;
+ *fbconfig = nullptr;
/* Set up the minimum attributes that we require and see if
* X can find us a visual matching those requirements. */
@@ -119,7 +119,7 @@ static XVisualInfo *x11_visualinfo_from_glx(Display *display,
__FILE__,
__LINE__);
- return NULL;
+ return nullptr;
}
glx_version = glx_major * 100 + glx_minor;
# ifndef WITH_X11_ALPHA
@@ -129,10 +129,10 @@ static XVisualInfo *x11_visualinfo_from_glx(Display *display,
# ifdef WITH_X11_ALPHA
if (needAlpha && glx_version >= 103 &&
(glXChooseFBConfig || (glXChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC)glXGetProcAddressARB(
- (const GLubyte *)"glXChooseFBConfig")) != NULL) &&
+ (const GLubyte *)"glXChooseFBConfig")) != nullptr) &&
(glXGetVisualFromFBConfig ||
(glXGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGPROC)glXGetProcAddressARB(
- (const GLubyte *)"glXGetVisualFromFBConfig")) != NULL)) {
+ (const GLubyte *)"glXGetVisualFromFBConfig")) != nullptr)) {
GHOST_X11_GL_GetAttributes(glx_attribs, 64, stereoVisual, needAlpha, true);
@@ -177,7 +177,7 @@ static XVisualInfo *x11_visualinfo_from_glx(Display *display,
/* Any sample level or even zero, which means oversampling disabled, is good
* but we need a valid visual to continue */
- if (visual != NULL) {
+ if (visual != nullptr) {
return visual;
}
}
@@ -189,7 +189,7 @@ static XVisualInfo *x11_visualinfo_from_glx(Display *display,
__FILE__,
__LINE__);
- return NULL;
+ return nullptr;
}
#endif // WITH_GL_EGL
@@ -211,8 +211,8 @@ GHOST_WindowX11::GHOST_WindowX11(GHOST_SystemX11 *system,
const bool is_debug)
: GHOST_Window(width, height, state, stereoVisual, exclusive),
m_display(display),
- m_visualInfo(NULL),
- m_fbconfig(NULL),
+ m_visualInfo(nullptr),
+ m_fbconfig(nullptr),
m_normal_state(GHOST_kWindowStateNormal),
m_system(system),
m_invalid_window(false),
@@ -221,11 +221,11 @@ GHOST_WindowX11::GHOST_WindowX11(GHOST_SystemX11 *system,
m_visible_cursor(None),
m_taskbar("blender.desktop"),
#ifdef WITH_XDND
- m_dropTarget(NULL),
+ m_dropTarget(nullptr),
#endif
m_tabletData(GHOST_TABLET_DATA_NONE),
#if defined(WITH_X11_XINPUT) && defined(X_HAVE_UTF8_STRING)
- m_xic(NULL),
+ m_xic(nullptr),
#endif
m_valid_setup(false),
m_is_debug_context(is_debug)
@@ -240,13 +240,13 @@ GHOST_WindowX11::GHOST_WindowX11(GHOST_SystemX11 *system,
#endif
}
else {
- XVisualInfo tmp = {0};
+ XVisualInfo tmp = {nullptr};
int n;
m_visualInfo = XGetVisualInfo(m_display, 0, &tmp, &n);
}
/* caller needs to check 'getValid()' */
- if (m_visualInfo == NULL) {
+ if (m_visualInfo == nullptr) {
fprintf(stderr, "initial window could not find the GLX extension\n");
return;
}
@@ -477,7 +477,7 @@ static Bool destroyICCallback(XIC /*xic*/, XPointer ptr, XPointer /*data*/)
GHOST_PRINT("XIM input context destroyed\n");
if (ptr) {
- *(XIC *)ptr = NULL;
+ *(XIC *)ptr = nullptr;
}
/* Ignored by X11. */
return True;
@@ -505,12 +505,12 @@ bool GHOST_WindowX11::createX11_XIC()
GHOST_X11_RES_CLASS,
XNDestroyCallback,
&destroy,
- NULL);
+ nullptr);
if (!m_xic)
return false;
unsigned long fevent;
- XGetICValues(m_xic, XNFilterEvents, &fevent, NULL);
+ XGetICValues(m_xic, XNFilterEvents, &fevent, nullptr);
XSelectInput(m_display,
m_window,
ExposureMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask |
@@ -586,7 +586,7 @@ void GHOST_WindowX11::setTitle(const char *title)
std::string GHOST_WindowX11::getTitle() const
{
- char *name = NULL;
+ char *name = nullptr;
XFetchName(m_display, m_window, &name);
std::string title = name ? name : "untitled";
@@ -719,8 +719,9 @@ void GHOST_WindowX11::icccmSetState(int state)
{
XEvent xev;
- if (state != IconicState)
+ if (state != IconicState) {
return;
+ }
xev.xclient.type = ClientMessage;
xev.xclient.serial = 0;
@@ -737,7 +738,7 @@ void GHOST_WindowX11::icccmSetState(int state)
&xev);
}
-int GHOST_WindowX11::icccmGetState(void) const
+int GHOST_WindowX11::icccmGetState() const
{
struct {
CARD32 state;
@@ -748,7 +749,7 @@ int GHOST_WindowX11::icccmGetState(void) const
int ret, format_ret;
CARD32 st;
- prop_ret = NULL;
+ prop_ret = nullptr;
ret = XGetWindowProperty(m_display,
m_window,
m_system->m_atom.WM_STATE,
@@ -761,7 +762,7 @@ int GHOST_WindowX11::icccmGetState(void) const
&num_ret,
&bytes_after,
((unsigned char **)&prop_ret));
- if ((ret == Success) && (prop_ret != NULL) && (num_ret == 2)) {
+ if ((ret == Success) && (prop_ret != nullptr) && (num_ret == 2)) {
st = prop_ret->state;
}
else {
@@ -786,10 +787,12 @@ void GHOST_WindowX11::netwmMaximized(bool set)
xev.xclient.message_type = m_system->m_atom._NET_WM_STATE;
xev.xclient.format = 32;
- if (set == True)
+ if (set == True) {
xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
- else
+ }
+ else {
xev.xclient.data.l[0] = _NET_WM_STATE_REMOVE;
+ }
xev.xclient.data.l[1] = m_system->m_atom._NET_WM_STATE_MAXIMIZED_HORZ;
xev.xclient.data.l[2] = m_system->m_atom._NET_WM_STATE_MAXIMIZED_VERT;
@@ -802,7 +805,7 @@ void GHOST_WindowX11::netwmMaximized(bool set)
&xev);
}
-bool GHOST_WindowX11::netwmIsMaximized(void) const
+bool GHOST_WindowX11::netwmIsMaximized() const
{
Atom *prop_ret;
unsigned long bytes_after, num_ret, i;
@@ -810,7 +813,7 @@ bool GHOST_WindowX11::netwmIsMaximized(void) const
bool st;
int format_ret, ret, count;
- prop_ret = NULL;
+ prop_ret = nullptr;
st = False;
ret = XGetWindowProperty(m_display,
m_window,
@@ -840,8 +843,9 @@ bool GHOST_WindowX11::netwmIsMaximized(void) const
}
}
- if (prop_ret)
+ if (prop_ret) {
XFree(prop_ret);
+ }
return st;
}
@@ -856,10 +860,12 @@ void GHOST_WindowX11::netwmFullScreen(bool set)
xev.xclient.message_type = m_system->m_atom._NET_WM_STATE;
xev.xclient.format = 32;
- if (set == True)
+ if (set == True) {
xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
- else
+ }
+ else {
xev.xclient.data.l[0] = _NET_WM_STATE_REMOVE;
+ }
xev.xclient.data.l[1] = m_system->m_atom._NET_WM_STATE_FULLSCREEN;
xev.xclient.data.l[2] = 0;
@@ -872,7 +878,7 @@ void GHOST_WindowX11::netwmFullScreen(bool set)
&xev);
}
-bool GHOST_WindowX11::netwmIsFullScreen(void) const
+bool GHOST_WindowX11::netwmIsFullScreen() const
{
Atom *prop_ret;
unsigned long bytes_after, num_ret, i;
@@ -880,7 +886,7 @@ bool GHOST_WindowX11::netwmIsFullScreen(void) const
bool st;
int format_ret, ret;
- prop_ret = NULL;
+ prop_ret = nullptr;
st = False;
ret = XGetWindowProperty(m_display,
m_window,
@@ -903,8 +909,9 @@ bool GHOST_WindowX11::netwmIsFullScreen(void) const
}
}
- if (prop_ret)
+ if (prop_ret) {
XFree(prop_ret);
+ }
return st;
}
@@ -913,10 +920,12 @@ void GHOST_WindowX11::motifFullScreen(bool set)
MotifWmHints hints;
hints.flags = MWM_HINTS_DECORATIONS;
- if (set == True)
+ if (set == True) {
hints.decorations = 0;
- else
+ }
+ else {
hints.decorations = 1;
+ }
XChangeProperty(m_display,
m_window,
@@ -928,7 +937,7 @@ void GHOST_WindowX11::motifFullScreen(bool set)
4);
}
-bool GHOST_WindowX11::motifIsFullScreen(void) const
+bool GHOST_WindowX11::motifIsFullScreen() const
{
MotifWmHints *prop_ret;
unsigned long bytes_after, num_ret;
@@ -936,7 +945,7 @@ bool GHOST_WindowX11::motifIsFullScreen(void) const
bool state;
int format_ret, st;
- prop_ret = NULL;
+ prop_ret = nullptr;
state = False;
st = XGetWindowProperty(m_display,
m_window,
@@ -952,13 +961,15 @@ bool GHOST_WindowX11::motifIsFullScreen(void) const
(unsigned char **)&prop_ret);
if ((st == Success) && prop_ret) {
if (prop_ret->flags & MWM_HINTS_DECORATIONS) {
- if (!prop_ret->decorations)
+ if (!prop_ret->decorations) {
state = True;
+ }
}
}
- if (prop_ret)
+ if (prop_ret) {
XFree(prop_ret);
+ }
return state;
}
@@ -973,14 +984,18 @@ GHOST_TWindowState GHOST_WindowX11::getState() const
* In the Iconic and Withdrawn state, the window
* is unmapped, so only need return a Minimized state.
*/
- if ((state == IconicState) || (state == WithdrawnState))
+ if ((state == IconicState) || (state == WithdrawnState)) {
state_ret = GHOST_kWindowStateMinimized;
- else if (netwmIsFullScreen() == True)
+ }
+ else if (netwmIsFullScreen() == True) {
state_ret = GHOST_kWindowStateFullScreen;
- else if (motifIsFullScreen() == True)
+ }
+ else if (motifIsFullScreen() == True) {
state_ret = GHOST_kWindowStateFullScreen;
- else if (netwmIsMaximized() == True)
+ }
+ else if (netwmIsMaximized() == True) {
state_ret = GHOST_kWindowStateMaximized;
+ }
return state_ret;
}
@@ -990,8 +1005,9 @@ GHOST_TSuccess GHOST_WindowX11::setState(GHOST_TWindowState state)
bool is_max, is_full, is_motif_full;
cur_state = getState();
- if (state == (int)cur_state)
+ if (state == (int)cur_state) {
return GHOST_kSuccess;
+ }
if (cur_state != GHOST_kWindowStateMinimized) {
/*
@@ -1008,16 +1024,20 @@ GHOST_TSuccess GHOST_WindowX11::setState(GHOST_TWindowState state)
is_motif_full = motifIsFullScreen();
- if (state == GHOST_kWindowStateNormal)
+ if (state == GHOST_kWindowStateNormal) {
state = m_normal_state;
+ }
if (state == GHOST_kWindowStateNormal) {
- if (is_max == True)
+ if (is_max == True) {
netwmMaximized(False);
- if (is_full == True)
+ }
+ if (is_full == True) {
netwmFullScreen(False);
- if (is_motif_full == True)
+ }
+ if (is_motif_full == True) {
motifFullScreen(False);
+ }
icccmSetState(NormalState);
return GHOST_kSuccess;
}
@@ -1027,17 +1047,21 @@ GHOST_TSuccess GHOST_WindowX11::setState(GHOST_TWindowState state)
* We can't change to full screen if the window
* isn't mapped.
*/
- if (cur_state == GHOST_kWindowStateMinimized)
+ if (cur_state == GHOST_kWindowStateMinimized) {
return GHOST_kFailure;
+ }
m_normal_state = cur_state;
- if (is_max == True)
+ if (is_max == True) {
netwmMaximized(False);
- if (is_full == False)
+ }
+ if (is_full == False) {
netwmFullScreen(True);
- if (is_motif_full == False)
+ }
+ if (is_motif_full == False) {
motifFullScreen(True);
+ }
return GHOST_kSuccess;
}
@@ -1046,15 +1070,19 @@ GHOST_TSuccess GHOST_WindowX11::setState(GHOST_TWindowState state)
* We can't change to Maximized if the window
* isn't mapped.
*/
- if (cur_state == GHOST_kWindowStateMinimized)
+ if (cur_state == GHOST_kWindowStateMinimized) {
return GHOST_kFailure;
+ }
- if (is_full == True)
+ if (is_full == True) {
netwmFullScreen(False);
- if (is_motif_full == True)
+ }
+ if (is_motif_full == True) {
motifFullScreen(False);
- if (is_max == False)
+ }
+ if (is_max == False) {
netwmMaximized(True);
+ }
return GHOST_kSuccess;
}
@@ -1111,8 +1139,9 @@ GHOST_TSuccess GHOST_WindowX11::setOrder(GHOST_TWindowOrder order)
XGetWindowAttributes(m_display, m_window, &attr);
/* Minimized windows give bad match error. */
- if (attr.map_state == IsViewable)
+ if (attr.map_state == IsViewable) {
XSetInputFocus(m_display, m_window, RevertToPointerRoot, CurrentTime);
+ }
XFlush(m_display);
}
else if (order == GHOST_kWindowOrderBottom) {
@@ -1137,7 +1166,7 @@ bool GHOST_WindowX11::isDialog() const
bool st;
int format_ret, ret;
- prop_ret = NULL;
+ prop_ret = nullptr;
st = False;
ret = XGetWindowProperty(m_display,
m_window,
@@ -1272,7 +1301,7 @@ GHOST_Context *GHOST_WindowX11::newDrawingContext(GHOST_TDrawingContextType type
#if defined(WITH_GL_PROFILE_CORE)
{
const char *version_major = (char *)glewGetString(GLEW_VERSION_MAJOR);
- if (version_major != NULL && version_major[0] == '1') {
+ if (version_major != nullptr && version_major[0] == '1') {
fprintf(stderr, "Error: GLEW version 2.0 and above is required.\n");
abort();
}
@@ -1327,10 +1356,10 @@ GHOST_Context *GHOST_WindowX11::newDrawingContext(GHOST_TDrawingContextType type
GHOST_OPENGL_GLX_RESET_NOTIFICATION_STRATEGY);
#endif
- if (context->initializeDrawingContext())
+ if (context->initializeDrawingContext()) {
return context;
- else
- delete context;
+ }
+ delete context;
}
#ifdef WITH_GL_EGL
@@ -1358,10 +1387,10 @@ GHOST_Context *GHOST_WindowX11::newDrawingContext(GHOST_TDrawingContextType type
GHOST_OPENGL_GLX_RESET_NOTIFICATION_STRATEGY);
#endif
- if (context->initializeDrawingContext())
+ if (context->initializeDrawingContext()) {
return context;
- else
- delete context;
+ }
+ delete context;
/* Ugly, but we get crashes unless a whole bunch of systems are patched. */
fprintf(stderr, "Error! Unsupported graphics card or driver.\n");
@@ -1372,7 +1401,7 @@ GHOST_Context *GHOST_WindowX11::newDrawingContext(GHOST_TDrawingContextType type
exit(1);
}
- return NULL;
+ return nullptr;
}
GHOST_TSuccess GHOST_WindowX11::getStandardCursor(GHOST_TStandardCursor g_cursor, Cursor &xcursor)
@@ -1488,8 +1517,9 @@ GHOST_TSuccess GHOST_WindowX11::setWindowCursorGrab(GHOST_TGrabCursorMode mode)
m_system->getCursorPosition(m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]);
setCursorGrabAccum(0, 0);
- if (mode == GHOST_kGrabHide)
+ if (mode == GHOST_kGrabHide) {
setWindowCursorVisibility(false);
+ }
}
#ifdef GHOST_X11_GRAB
XGrabPointer(m_display,
@@ -1580,10 +1610,12 @@ GHOST_TSuccess GHOST_WindowX11::setWindowCustomCursorShape(uint8_t *bitmap,
Pixmap bitmap_pix, mask_pix;
XColor fg, bg;
- if (XAllocNamedColor(m_display, colormap, "White", &fg, &fg) == 0)
+ if (XAllocNamedColor(m_display, colormap, "White", &fg, &fg) == 0) {
return GHOST_kFailure;
- if (XAllocNamedColor(m_display, colormap, "Black", &bg, &bg) == 0)
+ }
+ if (XAllocNamedColor(m_display, colormap, "Black", &bg, &bg) == 0) {
return GHOST_kFailure;
+ }
if (m_custom_cursor) {
XFreeCursor(m_display, m_custom_cursor);
@@ -1631,8 +1663,9 @@ GHOST_TSuccess GHOST_WindowX11::beginFullScreen() const
int err;
err = XGrabKeyboard(m_display, m_window, False, GrabModeAsync, GrabModeAsync, CurrentTime);
- if (err != GrabSuccess)
+ if (err != GrabSuccess) {
printf("XGrabKeyboard failed %d\n", err);
+ }
err = XGrabPointer(m_display,
m_window,
@@ -1643,8 +1676,9 @@ GHOST_TSuccess GHOST_WindowX11::beginFullScreen() const
m_window,
None,
CurrentTime);
- if (err != GrabSuccess)
+ if (err != GrabSuccess) {
printf("XGrabPointer failed %d\n", err);
+ }
return GHOST_kSuccess;
}
@@ -1664,7 +1698,7 @@ uint16_t GHOST_WindowX11::getDPIHint()
if (resMan) {
XrmDatabase xrdb = XrmGetStringDatabase(resMan);
if (xrdb) {
- char *type = NULL;
+ char *type = nullptr;
XrmValue val;
int success = XrmGetResource(xrdb, "Xft.dpi", "Xft.Dpi", &type, &val);