1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-18 20:10:29 +01:00

Refactoring handleMaximize() function

Simplify handleMaximize function for "not effective" case, where there
was couple of duplicate code, now there is one indentation level less
and readability increased.
This commit is contained in:
2017-02-21 18:56:16 +01:00
committed by Carlos R. Mafra
parent 9328ba5b3c
commit f3fdf0b8dd

View File

@@ -505,64 +505,68 @@ void handleMaximize(WWindow *wwin, int directions)
if ((wwin->flags.old_maximized & MAX_MAXIMUS) && if ((wwin->flags.old_maximized & MAX_MAXIMUS) &&
!(requested & MAX_MAXIMUS)) !(requested & MAX_MAXIMUS))
wMaximizeWindow(wwin, MAX_MAXIMUS | flags, head); wMaximizeWindow(wwin, MAX_MAXIMUS | flags, head);
else if (wPreferences.alt_half_maximize && else if (wPreferences.alt_half_maximize &&
current & MAX_HORIZONTAL && current & MAX_VERTICAL && current & MAX_HORIZONTAL && current & MAX_VERTICAL &&
requested & MAX_HORIZONTAL && requested & MAX_VERTICAL) requested & MAX_HORIZONTAL && requested & MAX_VERTICAL)
wUnmaximizeWindow(wwin); wUnmaximizeWindow(wwin);
else if (wPreferences.move_half_max_between_heads) {
/* Select windows, which are only horizontally or vertically /* Apply for window state, which is only horizontally or vertically
* maximized. Quarters cannot be handled here, since there is not * maximized. Quarters cannot be handled here, since there is not clear
* clear on which direction user intend to move such window. */ * on which direction user intend to move such window. */
if (current & (MAX_VERTICAL | MAX_HORIZONTAL)) { else if (wPreferences.move_half_max_between_heads &&
if (requested & MAX_LEFTHALF && current & MAX_LEFTHALF) { current & (MAX_VERTICAL | MAX_HORIZONTAL)) {
dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr, if (requested & MAX_LEFTHALF && current & MAX_LEFTHALF) {
head, DIRECTION_LEFT); dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr,
if (dest_head != -1) { head, DIRECTION_LEFT);
effective |= MAX_RIGHTHALF; if (dest_head != -1) {
effective |= MAX_VERTICAL; effective |= MAX_RIGHTHALF;
effective &= ~(MAX_HORIZONTAL | MAX_LEFTHALF); effective |= MAX_VERTICAL;
} effective &= ~(MAX_HORIZONTAL | MAX_LEFTHALF);
} else if (requested & MAX_RIGHTHALF && }
current & MAX_RIGHTHALF) { } else if (requested & MAX_RIGHTHALF &&
dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr, current & MAX_RIGHTHALF) {
head, DIRECTION_RIGHT); dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr,
if (dest_head != -1) { head, DIRECTION_RIGHT);
effective |= MAX_LEFTHALF; if (dest_head != -1) {
effective |= MAX_VERTICAL; effective |= MAX_LEFTHALF;
effective &= ~(MAX_HORIZONTAL | MAX_RIGHTHALF); effective |= MAX_VERTICAL;
} effective &= ~(MAX_HORIZONTAL | MAX_RIGHTHALF);
} else if (requested & MAX_TOPHALF && current & MAX_TOPHALF) { }
dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr, } else if (requested & MAX_TOPHALF && current & MAX_TOPHALF) {
head, DIRECTION_UP); dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr,
if (dest_head != -1) { head, DIRECTION_UP);
effective |= MAX_BOTTOMHALF; if (dest_head != -1) {
effective |= MAX_HORIZONTAL; effective |= MAX_BOTTOMHALF;
effective &= ~(MAX_VERTICAL | MAX_TOPHALF); effective |= MAX_HORIZONTAL;
} effective &= ~(MAX_VERTICAL | MAX_TOPHALF);
} else if (requested & MAX_BOTTOMHALF && }
current & MAX_BOTTOMHALF) { } else if (requested & MAX_BOTTOMHALF &&
dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr, current & MAX_BOTTOMHALF) {
head, DIRECTION_DOWN); dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr,
if (dest_head != -1) { head, DIRECTION_DOWN);
effective |= MAX_TOPHALF; if (dest_head != -1) {
effective |= MAX_HORIZONTAL; effective |= MAX_TOPHALF;
effective &= ~(MAX_VERTICAL | MAX_BOTTOMHALF); effective |= MAX_HORIZONTAL;
} effective &= ~(MAX_VERTICAL | MAX_BOTTOMHALF);
} if (dest_head != -1) }
/* tell wMaximizeWindow that we were using keyboard, not }
* mouse, so that it will use calculated head as }
* destination for move_half_max_between_heads feature,
* not from mouse pointer */ if (dest_head != -1)
wMaximizeWindow(wwin, (effective | flags | MAX_KEYBOARD), /* tell wMaximizeWindow that we were using keyboard, not mouse,
dest_head); * so that it will use calculated head as destination for
else if (!wPreferences.alt_half_maximize) * move_half_max_between_heads feature, not from mouse pointer */
wUnmaximizeWindow(wwin); wMaximizeWindow(wwin, (effective | flags | MAX_KEYBOARD),
} else if (!wPreferences.alt_half_maximize) dest_head);
wUnmaximizeWindow(wwin); else if (!wPreferences.alt_half_maximize)
} else if (!wPreferences.alt_half_maximize)
wUnmaximizeWindow(wwin); wUnmaximizeWindow(wwin);
return;
}
/* these alone mean vertical|horizontal toggle */ /* these alone mean vertical|horizontal toggle */
} else if ((effective == MAX_LEFTHALF) || if ((effective == MAX_LEFTHALF) ||
(effective == MAX_RIGHTHALF) || (effective == MAX_RIGHTHALF) ||
(effective == MAX_TOPHALF) || (effective == MAX_TOPHALF) ||
(effective == MAX_BOTTOMHALF)) (effective == MAX_BOTTOMHALF))
@@ -2080,14 +2084,9 @@ void wMakeWindowVisible(WWindow *wwin)
void movePionterToWindowCenter(WWindow *wwin) void movePionterToWindowCenter(WWindow *wwin)
{ {
if (!wPreferences.pointer_with_half_max_windows) { if (!wPreferences.pointer_with_half_max_windows)
wmessage("pointer_with_half_max_windows not set. do nothing");
return; return;
}
wmessage("move the pointer to: %dx%d",
wwin->frame_x + wwin->client.width / 2,
wwin->frame_y + wwin->client.height / 2);
XSelectInput(dpy, wwin->client_win, wwin->event_mask); XSelectInput(dpy, wwin->client_win, wwin->event_mask);
XWarpPointer(dpy, None, wwin->screen_ptr->root_win, 0, 0, 0, 0, XWarpPointer(dpy, None, wwin->screen_ptr->root_win, 0, 0, 0, 0,
wwin->frame_x + wwin->client.width / 2, wwin->frame_x + wwin->client.width / 2,