twin: Minor code cleanup and refactoring

Refactoring concerns active border code.

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
pull/371/head
Mavridis Philippe 11 months ago
parent becae3055b
commit 0339423ced
No known key found for this signature in database
GPG Key ID: F8D2D7E2F989A494

@ -110,16 +110,19 @@ enum ShadeMode
enum ActiveBorder enum ActiveBorder
{ {
ActiveTop, ActiveNone = 0,
ActiveTopRight,
ActiveRight, ActiveLeft = 1,
ActiveBottomRight, ActiveRight = 2,
ActiveBottom, ActiveTop = 4,
ActiveBottomLeft, ActiveBottom = 8,
ActiveLeft,
ActiveTopLeft, ActiveTopLeft = ActiveTop | ActiveLeft,
ACTIVE_BORDER_COUNT, ActiveTopRight = ActiveTop | ActiveRight,
ActiveNone ActiveBottomLeft = ActiveBottom | ActiveLeft,
ActiveBottomRight = ActiveBottom | ActiveRight,
ACTIVE_BORDER_COUNT
}; };
enum ActiveMaximizingMode enum ActiveMaximizingMode

@ -2534,8 +2534,9 @@ void Workspace::checkActiveBorder(const TQPoint &pos, Time now)
have_borders = true; have_borders = true;
} }
} }
if( !have_borders ) if (!have_borders) {
return; return;
}
// Mouse should not move more than this many pixels // Mouse should not move more than this many pixels
int distance_reset = activation_distance + 10; int distance_reset = activation_distance + 10;
@ -2575,49 +2576,37 @@ void Workspace::checkActiveBorder(const TQPoint &pos, Time now)
active_qtop = pos.y() < activeTop + active_height_quart, active_qtop = pos.y() < activeTop + active_height_quart,
active_qbottom = pos.y() > activeBottom - active_height_quart; active_qbottom = pos.y() > activeBottom - active_height_quart;
if (!active_left && !active_right && !active_top && !active_bottom) int border = ActiveNone;
return;
kdDebug() << "active border activated " if (active_left) border |= ActiveLeft;
<< pos.x() << ":" << pos.y() << endl; if (active_right) border |= ActiveRight;
if (active_top) border |= ActiveTop;
if (active_bottom) border |= ActiveBottom;
ActiveBorder border = ActiveNone; if (border == ActiveLeft || border == ActiveRight) {
if (active_left && active_top) { if (active_qtop) border |= ActiveTop;
border = ActiveTopLeft; if (active_qbottom) border |= ActiveBottom;
}
else if (active_right && active_top) {
border = ActiveTopRight;
}
else if (active_left && active_bottom) {
border = ActiveBottomLeft;
}
else if (active_right && active_bottom) {
border = ActiveBottomRight;
} }
else if (active_left) {
border = active_qtop ? ActiveTopLeft else if (border == ActiveTop || border == ActiveBottom) {
: (active_qbottom ? ActiveBottomLeft if (active_qleft) border |= ActiveLeft;
: ActiveLeft); if (active_qright) border |= ActiveRight;
} }
else if (active_right) {
border = active_qtop ? ActiveTopRight bool border_valid = false;
: (active_qbottom ? ActiveBottomRight for (int i = 0; i < ACTIVE_BORDER_COUNT; ++i) {
: ActiveRight); if (border == (ActiveBorder)i) {
border_valid = true;
} }
else if (active_top) {
border = active_qleft ? ActiveTopLeft
: (active_qright ? ActiveTopRight
: ActiveTop);
} }
else if (active_bottom) {
border = active_qleft ? ActiveBottomLeft if (!border_valid) {
: (active_qright ? ActiveBottomRight abort();
: ActiveBottom);
} }
else abort();
if( active_windows[border] == None ) if (border == ActiveNone || active_windows[border] == None) {
return; return;
}
if ((active_current_border == border) && if ((active_current_border == border) &&
(timestampDiff(active_time_last, now) < treshold_reset) && (timestampDiff(active_time_last, now) < treshold_reset) &&
@ -2625,10 +2614,6 @@ void Workspace::checkActiveBorder(const TQPoint &pos, Time now)
((pos-active_push_point).manhattanLength() < distance_reset)) ((pos-active_push_point).manhattanLength() < distance_reset))
{ {
active_time_last = now; active_time_last = now;
kdDebug() << "time diff between first time and now is: "
<< timestampDiff(active_time_first, now)
<< " vs threshold " << treshold_set << endl;
if (timestampDiff(active_time_first, now) > treshold_set) if (timestampDiff(active_time_first, now) > treshold_set)
{ {
active_time_last_trigger = now; active_time_last_trigger = now;
@ -2642,7 +2627,7 @@ void Workspace::checkActiveBorder(const TQPoint &pos, Time now)
if (options->activeBorders() == Options::ActiveSwitchAlways || if (options->activeBorders() == Options::ActiveSwitchAlways ||
options->activeBorders() == Options::ActiveSwitchOnMove) options->activeBorders() == Options::ActiveSwitchOnMove)
{ {
activeBorderSwitchDesktop(border, pos); activeBorderSwitchDesktop((ActiveBorder)border, pos);
return; // Don't reset cursor position return; // Don't reset cursor position
} }
@ -2662,7 +2647,7 @@ void Workspace::checkActiveBorder(const TQPoint &pos, Time now)
{ {
if (!movingClient->isResizable()) return; if (!movingClient->isResizable()) return;
movingClient->setActiveBorderMode(ActiveTilingMode); movingClient->setActiveBorderMode(ActiveTilingMode);
movingClient->setActiveBorder(border); movingClient->setActiveBorder((ActiveBorder)border);
movingClient->setActiveBorderMaximizing(true); movingClient->setActiveBorderMaximizing(true);
} }
@ -2676,7 +2661,7 @@ void Workspace::checkActiveBorder(const TQPoint &pos, Time now)
// Desktop switching // Desktop switching
if (options->activeBorders() == Options::ActiveSwitchAlways && isSide) if (options->activeBorders() == Options::ActiveSwitchAlways && isSide)
{ {
activeBorderSwitchDesktop(border, pos); activeBorderSwitchDesktop((ActiveBorder)border, pos);
return; // Don't reset cursor position return; // Don't reset cursor position
} }
} }
@ -2684,7 +2669,7 @@ void Workspace::checkActiveBorder(const TQPoint &pos, Time now)
} }
else else
{ {
active_current_border = border; active_current_border = (ActiveBorder)border;
active_time_first = now; active_time_first = now;
active_time_last = now; active_time_last = now;
active_push_point = pos; active_push_point = pos;
@ -2693,11 +2678,11 @@ void Workspace::checkActiveBorder(const TQPoint &pos, Time now)
if ((options->activeBorders() == Options::ActiveSwitchAlways && !movingClient) || if ((options->activeBorders() == Options::ActiveSwitchAlways && !movingClient) ||
activation_distance < 2) activation_distance < 2)
{ {
// reset the pointer to find out whether the user is really pushing // Reset the pointer to find out whether the user is really pushing
// (the direction back from which it came, starting from top clockwise) // (ordered according to enum ActiveBorder minus ActiveNone)
const int xdiff[ ACTIVE_BORDER_COUNT ] = { 0, -1, -1, -1, 0, 1, 1, 1 }; const int xdiff[ACTIVE_BORDER_COUNT] = {1, -1, 0, 0, 1, -1, 1, -1};
const int ydiff[ ACTIVE_BORDER_COUNT ] = { 1, 1, 0, -1, -1, -1, 0, 1 }; const int ydiff[ACTIVE_BORDER_COUNT] = {0, 0, 1, -1, 1, 1, -1, -1};
TQCursor::setPos(pos.x() + xdiff[border], pos.y() + ydiff[border]); TQCursor::setPos(pos.x() + xdiff[border - 1], pos.y() + ydiff[border - 1]);
} }
} }

Loading…
Cancel
Save