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-07-08 12:36:33 +0300
committerCampbell Barton <campbell@blender.org>2022-07-08 12:39:11 +0300
commit47616992f89502b93e7b982ee95923f2e6f45f01 (patch)
tree876c247c1f0138222e58dbd73e18dd66c9fbbc82
parent418d82af288a4ffdc805f950dc4b7b49437d311f (diff)
GHOST: use ELEM/ARRAY_SIZE/UNPACK macros to avoid repetition
Also use UNLIKELY macro for checks for very unlikely scenarios.
-rw-r--r--intern/ghost/intern/GHOST_DropTargetX11.cpp3
-rw-r--r--intern/ghost/intern/GHOST_NDOFManager.cpp3
-rw-r--r--intern/ghost/intern/GHOST_SystemWayland.cpp69
-rw-r--r--intern/ghost/intern/GHOST_SystemX11.cpp32
-rw-r--r--intern/ghost/intern/GHOST_WindowWayland.cpp17
-rw-r--r--intern/ghost/intern/GHOST_WindowX11.cpp11
6 files changed, 69 insertions, 66 deletions
diff --git a/intern/ghost/intern/GHOST_DropTargetX11.cpp b/intern/ghost/intern/GHOST_DropTargetX11.cpp
index 900e46c3732..252a8bfd095 100644
--- a/intern/ghost/intern/GHOST_DropTargetX11.cpp
+++ b/intern/ghost/intern/GHOST_DropTargetX11.cpp
@@ -7,6 +7,7 @@
#include "GHOST_DropTargetX11.h"
#include "GHOST_Debug.h"
+#include "GHOST_utildefines.h"
#include <cassert>
#include <cctype>
@@ -34,7 +35,7 @@ int GHOST_DropTargetX11::m_refCounter = 0;
void GHOST_DropTargetX11::Initialize()
{
Display *display = m_system->getXDisplay();
- int dndTypesCount = sizeof(m_dndMimeTypes) / sizeof(char *);
+ int dndTypesCount = ARRAY_SIZE(m_dndMimeTypes);
int counter;
xdnd_init(&m_dndClass, display);
diff --git a/intern/ghost/intern/GHOST_NDOFManager.cpp b/intern/ghost/intern/GHOST_NDOFManager.cpp
index 2298ba86521..d58fb90f63e 100644
--- a/intern/ghost/intern/GHOST_NDOFManager.cpp
+++ b/intern/ghost/intern/GHOST_NDOFManager.cpp
@@ -5,6 +5,7 @@
#include "GHOST_EventKey.h"
#include "GHOST_EventNDOF.h"
#include "GHOST_WindowManager.h"
+#include "GHOST_utildefines.h"
#include <climits>
#include <cmath>
@@ -128,7 +129,7 @@ static const NDOF_ButtonT Generic_HID_map[] = {
NDOF_BUTTON_C,
};
-static const int genericButtonCount = sizeof(Generic_HID_map) / sizeof(NDOF_ButtonT);
+static const int genericButtonCount = ARRAY_SIZE(Generic_HID_map);
GHOST_NDOFManager::GHOST_NDOFManager(GHOST_System &sys)
: m_system(sys),
diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp
index 164531f3847..f6406d098ca 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -13,6 +13,7 @@
#include "GHOST_EventWheel.h"
#include "GHOST_TimerManager.h"
#include "GHOST_WindowManager.h"
+#include "GHOST_utildefines.h"
#include "GHOST_ContextEGL.h"
@@ -628,7 +629,7 @@ static GHOST_TKey xkb_map_gkey_or_scan_code(const xkb_keysym_t sym, const uint32
{
GHOST_TKey gkey = xkb_map_gkey(sym);
- if (gkey == GHOST_kKeyUnknown) {
+ if (UNLIKELY(gkey == GHOST_kKeyUnknown)) {
/* Fall back to physical location for keys that would otherwise do nothing. */
switch (key) {
case KEY_GRAVE: {
@@ -774,7 +775,7 @@ static void relative_pointer_handle_relative_motion_impl(input_t *input,
bounds.m_t = wl_fixed_from_int(bounds.m_t) / scale;
bounds.m_r = wl_fixed_from_int(bounds.m_r) / scale;
bounds.m_b = wl_fixed_from_int(bounds.m_b) / scale;
- bounds.clampPoint(input->pointer.xy[0], input->pointer.xy[1]);
+ bounds.clampPoint(UNPACK2(input->pointer.xy));
}
#endif
input->system->pushEvent(new GHOST_EventCursor(input->system->getMilliSeconds(),
@@ -831,7 +832,7 @@ static void dnd_events(const input_t *const input, const GHOST_TEventType event)
const uint64_t time = input->system->getMilliSeconds();
for (const std::string &type : mime_preference_order) {
input->system->pushEvent(new GHOST_EventDragnDrop(
- time, event, mime_dnd.at(type), win, event_xy[0], event_xy[1], nullptr));
+ time, event, mime_dnd.at(type), win, UNPACK2(event_xy), nullptr));
}
}
}
@@ -841,7 +842,7 @@ static std::string read_pipe(data_offer_t *data_offer,
std::mutex *mutex)
{
int pipefd[2];
- if (pipe(pipefd) != 0) {
+ if (UNLIKELY(pipe(pipefd) != 0)) {
return {};
}
wl_data_offer_receive(data_offer->id, mime_receive.c_str(), pipefd[1]);
@@ -1076,7 +1077,7 @@ static void data_device_handle_drop(void *data, struct wl_data_device * /*wl_dat
data_offer_t *data_offer,
wl_surface *surface,
const std::string mime_receive) {
- const wl_fixed_t xy[2] = {data_offer->dnd.xy[0], data_offer->dnd.xy[1]};
+ const wl_fixed_t xy[2] = {UNPACK2(data_offer->dnd.xy)};
const std::string data = read_pipe(data_offer, mime_receive, nullptr);
@@ -1126,7 +1127,7 @@ static void data_device_handle_drop(void *data, struct wl_data_device * /*wl_dat
wl_fixed_to_int(scale * xy[1]),
flist));
}
- else if (mime_receive == mime_text_plain || mime_receive == mime_text_utf8) {
+ else if (ELEM(mime_receive, mime_text_plain, mime_text_utf8)) {
/* TODO: enable use of internal functions 'txt_insert_buf' and
* 'text_update_edited' to behave like dropped text was pasted. */
}
@@ -1602,8 +1603,8 @@ static void tablet_tool_handle_tilt(void *data,
/* Map degrees to `-1.0..1.0`. */
td.Xtilt = wl_fixed_to_double(tilt_x) / 90.0f;
td.Ytilt = wl_fixed_to_double(tilt_y) / 90.0f;
- td.Xtilt = td.Xtilt < -1.0f ? -1.0f : (td.Xtilt > 1.0f ? 1.0f : td.Xtilt);
- td.Ytilt = td.Ytilt < -1.0f ? -1.0f : (td.Ytilt > 1.0f ? 1.0f : td.Ytilt);
+ CLAMP(td.Xtilt, -1.0f, 1.0f);
+ CLAMP(td.Ytilt, -1.0f, 1.0f);
}
static void tablet_tool_handle_rotation(void * /*data*/,
@@ -2559,7 +2560,7 @@ int GHOST_SystemWayland::setConsoleWindowState(GHOST_TConsoleWindowState /*actio
GHOST_TSuccess GHOST_SystemWayland::getModifierKeys(GHOST_ModifierKeys &keys) const
{
- if (d->inputs.empty()) {
+ if (UNLIKELY(d->inputs.empty())) {
return GHOST_kFailure;
}
@@ -2594,7 +2595,7 @@ GHOST_TSuccess GHOST_SystemWayland::getModifierKeys(GHOST_ModifierKeys &keys) co
GHOST_TSuccess GHOST_SystemWayland::getButtons(GHOST_Buttons &buttons) const
{
- if (d->inputs.empty()) {
+ if (UNLIKELY(d->inputs.empty())) {
return GHOST_kFailure;
}
input_t *input = d->inputs[0];
@@ -2616,7 +2617,7 @@ char *GHOST_SystemWayland::getClipboard(bool /*selection*/) const
void GHOST_SystemWayland::putClipboard(const char *buffer, bool /*selection*/) const
{
- if (!d->data_device_manager || d->inputs.empty()) {
+ if (UNLIKELY(!d->data_device_manager || d->inputs.empty())) {
return;
}
@@ -2690,7 +2691,7 @@ GHOST_TSuccess GHOST_SystemWayland::getCursorPositionClientRelative(const GHOST_
int32_t &x,
int32_t &y) const
{
- if (d->inputs.empty()) {
+ if (UNLIKELY(d->inputs.empty())) {
return GHOST_kFailure;
}
input_t *input = d->inputs[0];
@@ -2706,7 +2707,7 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorPositionClientRelative(GHOST_IWindo
const int32_t x,
const int32_t y)
{
- if (d->inputs.empty()) {
+ if (UNLIKELY(d->inputs.empty())) {
return GHOST_kFailure;
}
input_t *input = d->inputs[0];
@@ -2716,7 +2717,7 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorPositionClientRelative(GHOST_IWindo
GHOST_TSuccess GHOST_SystemWayland::getCursorPosition(int32_t &x, int32_t &y) const
{
- if (d->inputs.empty()) {
+ if (UNLIKELY(d->inputs.empty())) {
return GHOST_kFailure;
}
input_t *input = d->inputs[0];
@@ -2734,7 +2735,7 @@ GHOST_TSuccess GHOST_SystemWayland::getCursorPosition(int32_t &x, int32_t &y) co
GHOST_TSuccess GHOST_SystemWayland::setCursorPosition(const int32_t x, const int32_t y)
{
- if (d->inputs.empty()) {
+ if (UNLIKELY(d->inputs.empty())) {
return GHOST_kFailure;
}
input_t *input = d->inputs[0];
@@ -3054,7 +3055,7 @@ static bool cursor_is_software(const GHOST_TGrabCursorMode mode, const bool use_
GHOST_TSuccess GHOST_SystemWayland::setCursorShape(const GHOST_TStandardCursor shape)
{
- if (d->inputs.empty()) {
+ if (UNLIKELY(d->inputs.empty())) {
return GHOST_kFailure;
}
auto cursor_find = cursors.find(shape);
@@ -3115,7 +3116,7 @@ GHOST_TSuccess GHOST_SystemWayland::setCustomCursorShape(uint8_t *bitmap,
const int hotY,
const bool /*canInvertColor*/)
{
- if (d->inputs.empty()) {
+ if (UNLIKELY(d->inputs.empty())) {
return GHOST_kFailure;
}
@@ -3145,18 +3146,18 @@ GHOST_TSuccess GHOST_SystemWayland::setCustomCursorShape(uint8_t *bitmap,
free(tmpname);
#endif
- if (fd < 0) {
+ if (UNLIKELY(fd < 0)) {
return GHOST_kFailure;
}
- if (posix_fallocate(fd, 0, int32_t(cursor->file_buffer->size)) != 0) {
+ if (UNLIKELY(posix_fallocate(fd, 0, int32_t(cursor->file_buffer->size)) != 0)) {
return GHOST_kFailure;
}
cursor->file_buffer->data = mmap(
nullptr, cursor->file_buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
- if (cursor->file_buffer->data == MAP_FAILED) {
+ if (UNLIKELY(cursor->file_buffer->data == MAP_FAILED)) {
cursor->file_buffer->data = nullptr;
close(fd);
return GHOST_kFailure;
@@ -3239,7 +3240,7 @@ GHOST_TSuccess GHOST_SystemWayland::getCursorBitmap(GHOST_CursorBitmapRef *bitma
GHOST_TSuccess GHOST_SystemWayland::setCursorVisibility(const bool visible)
{
- if (d->inputs.empty()) {
+ if (UNLIKELY(d->inputs.empty())) {
return GHOST_kFailure;
}
@@ -3263,7 +3264,7 @@ bool GHOST_SystemWayland::supportsWindowPosition()
bool GHOST_SystemWayland::getCursorGrabUseSoftwareDisplay(const GHOST_TGrabCursorMode mode)
{
- if (d->inputs.empty()) {
+ if (UNLIKELY(d->inputs.empty())) {
return false;
}
@@ -3309,7 +3310,7 @@ static input_grab_state_t input_grab_state_from_mode(const GHOST_TGrabCursorMode
/* Initialize all members. */
const struct input_grab_state_t grab_state = {
/* Warping happens to require software cursor which also hides. */
- .use_lock = (mode == GHOST_kGrabWrap || mode == GHOST_kGrabHide) || use_software_confine,
+ .use_lock = ELEM(mode, GHOST_kGrabWrap, GHOST_kGrabHide) || use_software_confine,
.use_confine = (mode == GHOST_kGrabNormal) && (use_software_confine == false),
};
return grab_state;
@@ -3455,11 +3456,11 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod
const int scale)
{
/* Ignore, if the required protocols are not supported. */
- if (!d->relative_pointer_manager || !d->pointer_constraints) {
+ if (UNLIKELY(!d->relative_pointer_manager || !d->pointer_constraints)) {
return GHOST_kFailure;
}
- if (d->inputs.empty()) {
+ if (UNLIKELY(d->inputs.empty())) {
return GHOST_kFailure;
}
/* No change, success. */
@@ -3483,9 +3484,7 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod
mode, use_software_confine);
/* Check for wrap as #supportsCursorWarp isn't supported. */
- const bool use_visible = !(((mode == GHOST_kGrabHide) || (mode == GHOST_kGrabWrap)) ||
- use_software_confine);
-
+ const bool use_visible = !(ELEM(mode, GHOST_kGrabHide, GHOST_kGrabWrap) || use_software_confine);
const bool is_hardware_cursor = !cursor_is_software(mode, use_software_confine);
/* Only hide so the cursor is not made visible before it's location is restored.
@@ -3505,7 +3504,7 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod
if (mode_current == GHOST_kGrabWrap) {
/* Since this call is initiated by Blender, we can be sure the window wasn't closed
* by logic outside this function - as the window was needed to make this call. */
- int32_t xy_new[2] = {input->pointer.xy[0], input->pointer.xy[1]};
+ int32_t xy_new[2] = {UNPACK2(input->pointer.xy)};
GHOST_Rect bounds_scale;
@@ -3514,7 +3513,7 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod
bounds_scale.m_r = wl_fixed_from_int(wrap_bounds->m_r) / scale;
bounds_scale.m_b = wl_fixed_from_int(wrap_bounds->m_b) / scale;
- bounds_scale.wrapPoint(xy_new[0], xy_new[1], 0, wrap_axis);
+ bounds_scale.wrapPoint(UNPACK2(xy_new), 0, wrap_axis);
/* Push an event so the new location is registered. */
if ((xy_new[0] != input->pointer.xy[0]) || (xy_new[1] != input->pointer.xy[1])) {
@@ -3528,8 +3527,7 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod
input->pointer.xy[0] = xy_new[0];
input->pointer.xy[1] = xy_new[1];
- zwp_locked_pointer_v1_set_cursor_position_hint(
- input->locked_pointer, xy_new[0], xy_new[1]);
+ zwp_locked_pointer_v1_set_cursor_position_hint(input->locked_pointer, UNPACK2(xy_new));
wl_surface_commit(surface);
}
else if (mode_current == GHOST_kGrabHide) {
@@ -3539,16 +3537,15 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod
wl_fixed_from_int(init_grab_xy[0]) / scale,
wl_fixed_from_int(init_grab_xy[1]) / scale,
};
- zwp_locked_pointer_v1_set_cursor_position_hint(
- input->locked_pointer, xy_next[0], xy_next[1]);
+ zwp_locked_pointer_v1_set_cursor_position_hint(input->locked_pointer, UNPACK2(xy_next));
wl_surface_commit(surface);
}
}
#ifdef USE_GNOME_CONFINE_HACK
else if (mode_current == GHOST_kGrabNormal) {
if (was_software_confine) {
- zwp_locked_pointer_v1_set_cursor_position_hint(
- input->locked_pointer, input->pointer.xy[0], input->pointer.xy[1]);
+ zwp_locked_pointer_v1_set_cursor_position_hint(input->locked_pointer,
+ UNPACK2(input->pointer.xy));
wl_surface_commit(surface);
}
}
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index 0023ff639f4..5e549b54afd 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -25,6 +25,7 @@
#ifdef WITH_INPUT_NDOF
# include "GHOST_NDOFManagerUnix.h"
#endif
+#include "GHOST_utildefines.h"
#ifdef WITH_XDND
# include "GHOST_DropTargetX11.h"
@@ -663,7 +664,7 @@ bool GHOST_SystemX11::processEvents(bool waitForEvent)
/* open connection to XIM server and create input context (XIC)
* when receiving the first FocusIn or KeyPress event after startup,
* or recover XIM and XIC when the XIM server has been restarted */
- if (xevent.type == FocusIn || xevent.type == KeyPress) {
+ if (ELEM(xevent.type, FocusIn, KeyPress)) {
if (!m_xim && openX11_IM()) {
GHOST_PRINT("Connected to XIM server\n");
}
@@ -724,9 +725,9 @@ bool GHOST_SystemX11::processEvents(bool waitForEvent)
* in order to confirm the window is active. */
XPeekEvent(m_display, &xev_next);
- if (xev_next.type == KeyPress || xev_next.type == KeyRelease) {
- /* XK_Hyper_L/R currently unused */
- const static KeySym modifiers[8] = {
+ if (ELEM(xev_next.type, KeyPress, KeyRelease)) {
+ /* XK_Hyper_L/R currently unused. */
+ const static KeySym modifiers[] = {
XK_Shift_L,
XK_Shift_R,
XK_Control_L,
@@ -737,7 +738,7 @@ bool GHOST_SystemX11::processEvents(bool waitForEvent)
XK_Super_R,
};
- for (int i = 0; i < (int)(sizeof(modifiers) / sizeof(*modifiers)); i++) {
+ for (int i = 0; i < (int)ARRAY_SIZE(modifiers); i++) {
KeyCode kc = XKeysymToKeycode(m_display, modifiers[i]);
if (kc != 0 && ((xevent.xkeymap.key_vector[kc >> 3] >> (kc & 7)) & 1) != 0) {
pushEvent(new GHOST_EventKey(getMilliSeconds(),
@@ -822,7 +823,7 @@ void GHOST_SystemX11::processEvent(XEvent *xe)
/* Detect auto-repeat. */
bool is_repeat = false;
- if (xe->type == KeyPress || xe->type == KeyRelease) {
+ if (ELEM(xe->type, KeyPress, KeyRelease)) {
XKeyEvent *xke = &(xe->xkey);
/* Set to true if this key will repeat. */
@@ -889,9 +890,11 @@ void GHOST_SystemX11::processEvent(XEvent *xe)
if (xe->type == xi_presence) {
XDevicePresenceNotifyEvent *notify_event = (XDevicePresenceNotifyEvent *)xe;
- if ((notify_event->devchange == DeviceEnabled) ||
- (notify_event->devchange == DeviceDisabled) ||
- (notify_event->devchange == DeviceAdded) || (notify_event->devchange == DeviceRemoved)) {
+ if (ELEM(notify_event->devchange,
+ DeviceEnabled,
+ DeviceDisabled,
+ DeviceAdded,
+ DeviceRemoved)) {
refreshXInputDevices();
/* update all window events */
@@ -1164,7 +1167,7 @@ void GHOST_SystemX11::processEvent(XEvent *xe)
len = Xutf8LookupString(xic, xke, utf8_buf, len, &key_sym, &status);
}
- if ((status == XLookupChars || status == XLookupBoth)) {
+ if (ELEM(status, XLookupChars, XLookupBoth)) {
if ((unsigned char)utf8_buf[0] >= 32) { /* not an ascii control character */
/* do nothing for now, this is valid utf8 */
}
@@ -1449,8 +1452,7 @@ void GHOST_SystemX11::processEvent(XEvent *xe)
nxe.xselection.time = xse->time;
/* Check to see if the requester is asking for String */
- if (xse->target == utf8_string || xse->target == string || xse->target == compound_text ||
- xse->target == c_string) {
+ if (ELEM(xse->target, utf8_string, string, compound_text, c_string)) {
if (xse->selection == XInternAtom(m_display, "PRIMARY", False)) {
XChangeProperty(m_display,
xse->requestor,
@@ -1503,7 +1505,7 @@ void GHOST_SystemX11::processEvent(XEvent *xe)
default: {
#ifdef WITH_X11_XINPUT
for (GHOST_TabletX11 &xtablet : m_xtablets) {
- if (xe->type == xtablet.MotionEvent || xe->type == xtablet.PressEvent) {
+ if (ELEM(xe->type, xtablet.MotionEvent, xtablet.PressEvent)) {
XDeviceMotionEvent *data = (XDeviceMotionEvent *)xe;
if (data->deviceid != xtablet.ID) {
continue;
@@ -2574,7 +2576,7 @@ int GHOST_X11_ApplicationIOErrorHandler(Display * /*display*/)
static bool is_filler_char(char c)
{
- return isspace(c) || c == '_' || c == '-' || c == ';' || c == ':';
+ return isspace(c) || ELEM(c, '_', '-', ';', ':');
}
/* These C functions are copied from Wine 3.12's `wintab.c` */
@@ -2674,7 +2676,7 @@ void GHOST_SystemX11::refreshXInputDevices()
XFree((void *)device_type);
}
- if (!(tablet_mode == GHOST_kTabletModeStylus || tablet_mode == GHOST_kTabletModeEraser)) {
+ if (!ELEM(tablet_mode, GHOST_kTabletModeStylus, GHOST_kTabletModeEraser)) {
continue;
}
diff --git a/intern/ghost/intern/GHOST_WindowWayland.cpp b/intern/ghost/intern/GHOST_WindowWayland.cpp
index a04ff23a1a1..a5177a25ef7 100644
--- a/intern/ghost/intern/GHOST_WindowWayland.cpp
+++ b/intern/ghost/intern/GHOST_WindowWayland.cpp
@@ -8,6 +8,7 @@
#include "GHOST_SystemWayland.h"
#include "GHOST_WaylandUtils.h"
#include "GHOST_WindowManager.h"
+#include "GHOST_utildefines.h"
#include "GHOST_Event.h"
@@ -215,7 +216,7 @@ static void frame_handle_configure(struct libdecor_frame *frame,
win->size[0] = win->scale * size_next[0];
win->size[1] = win->scale * size_next[1];
- wl_egl_window_resize(win->egl_window, win->size[0], win->size[1], 0, 0);
+ wl_egl_window_resize(win->egl_window, UNPACK2(win->size), 0, 0);
win->w->notify_size();
if (!libdecor_configuration_get_window_state(configuration, &window_state)) {
@@ -228,7 +229,7 @@ static void frame_handle_configure(struct libdecor_frame *frame,
win->is_active ? win->w->activate() : win->w->deactivate();
- state = libdecor_state_new(size_next[0], size_next[1]);
+ state = libdecor_state_new(UNPACK2(size_next));
libdecor_frame_commit(frame, state, configuration);
libdecor_state_free(state);
@@ -298,7 +299,7 @@ static void xdg_surface_handle_configure(void *data,
if (win->size_pending[0] != 0 && win->size_pending[1] != 0) {
win->size[0] = win->size_pending[0];
win->size[1] = win->size_pending[1];
- wl_egl_window_resize(win->egl_window, win->size[0], win->size[1], 0, 0);
+ wl_egl_window_resize(win->egl_window, UNPACK2(win->size), 0, 0);
win->size_pending[0] = 0;
win->size_pending[1] = 0;
win->w->notify_size();
@@ -433,7 +434,7 @@ GHOST_WindowWayland::GHOST_WindowWayland(GHOST_SystemWayland *system,
m_system->decor_context(), w->wl_surface, &libdecor_frame_iface, w);
libdecor_frame_map(w->decor_frame);
- libdecor_frame_set_min_content_size(w->decor_frame, size_min[0], size_min[1]);
+ libdecor_frame_set_min_content_size(w->decor_frame, UNPACK2(size_min));
if (parentWindow) {
libdecor_frame_set_parent(
@@ -443,7 +444,7 @@ GHOST_WindowWayland::GHOST_WindowWayland(GHOST_SystemWayland *system,
w->xdg_surface = xdg_wm_base_get_xdg_surface(m_system->xdg_shell(), w->wl_surface);
w->xdg_toplevel = xdg_surface_get_toplevel(w->xdg_surface);
- xdg_toplevel_set_min_size(w->xdg_toplevel, size_min[0], size_min[1]);
+ xdg_toplevel_set_min_size(w->xdg_toplevel, UNPACK2(size_min));
if (m_system->xdg_decoration_manager()) {
w->xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(
@@ -569,7 +570,7 @@ void GHOST_WindowWayland::getWindowBounds(GHOST_Rect &bounds) const
void GHOST_WindowWayland::getClientBounds(GHOST_Rect &bounds) const
{
- bounds.set(0, 0, w->size[0], w->size[1]);
+ bounds.set(0, 0, UNPACK2(w->size));
}
GHOST_TSuccess GHOST_WindowWayland::setClientWidth(const uint32_t width)
@@ -760,7 +761,7 @@ void GHOST_WindowWayland::setOpaque() const
/* Make the window opaque. */
region = wl_compositor_create_region(m_system->compositor());
- wl_region_add(region, 0, 0, w->size[0], w->size[1]);
+ wl_region_add(region, 0, 0, UNPACK2(w->size));
wl_surface_set_opaque_region(w->surface, region);
wl_region_destroy(region);
}
@@ -890,7 +891,7 @@ bool GHOST_WindowWayland::outputs_changed_update_scale()
{
uint32_t dpi_next;
const int scale_next = outputs_max_scale_or_default(this->outputs(), 0, &dpi_next);
- if (scale_next == 0) {
+ if (UNLIKELY(scale_next == 0)) {
return false;
}
diff --git a/intern/ghost/intern/GHOST_WindowX11.cpp b/intern/ghost/intern/GHOST_WindowX11.cpp
index ac7a476c76f..01045c516c1 100644
--- a/intern/ghost/intern/GHOST_WindowX11.cpp
+++ b/intern/ghost/intern/GHOST_WindowX11.cpp
@@ -17,6 +17,7 @@
#include "GHOST_IconX11.h"
#include "GHOST_SystemX11.h"
#include "GHOST_WindowX11.h"
+#include "GHOST_utildefines.h"
#ifdef WITH_XDND
# include "GHOST_DropTargetX11.h"
@@ -296,7 +297,7 @@ GHOST_WindowX11::GHOST_WindowX11(GHOST_SystemX11 *system,
GHOST_PRINT("Set drop target\n");
#endif
- if (state == GHOST_kWindowStateMaximized || state == GHOST_kWindowStateFullScreen) {
+ if (ELEM(state, GHOST_kWindowStateMaximized, GHOST_kWindowStateFullScreen)) {
Atom atoms[2];
int count = 0;
if (state == GHOST_kWindowStateMaximized) {
@@ -412,7 +413,7 @@ GHOST_WindowX11::GHOST_WindowX11(GHOST_SystemX11 *system,
32,
PropModeReplace,
(unsigned char *)BLENDER_ICONS_WM_X11,
- sizeof(BLENDER_ICONS_WM_X11) / sizeof(unsigned long));
+ ARRAY_SIZE(BLENDER_ICONS_WM_X11));
}
/* set the process ID (_NET_WM_PID) */
@@ -984,7 +985,7 @@ 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 (ELEM(state, IconicState, WithdrawnState)) {
state_ret = GHOST_kWindowStateMinimized;
}
else if (netwmIsFullScreen() == True) {
@@ -1514,7 +1515,7 @@ GHOST_TSuccess GHOST_WindowX11::setWindowCursorGrab(GHOST_TGrabCursorMode mode)
{
if (mode != GHOST_kGrabDisable) {
if (mode != GHOST_kGrabNormal) {
- m_system->getCursorPosition(m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]);
+ m_system->getCursorPosition(UNPACK2(m_cursorGrabInitPos));
setCursorGrabAccum(0, 0);
if (mode == GHOST_kGrabHide) {
@@ -1535,7 +1536,7 @@ GHOST_TSuccess GHOST_WindowX11::setWindowCursorGrab(GHOST_TGrabCursorMode mode)
}
else {
if (m_cursorGrab == GHOST_kGrabHide) {
- m_system->setCursorPosition(m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]);
+ m_system->setCursorPosition(UNPACK2(m_cursorGrabInitPos));
}
if (m_cursorGrab != GHOST_kGrabNormal) {