twin: Minor code cleanup and refactoring

Refactoring concerns active border code.

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
pull/371/head
Mavridis Philippe 10 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
{
ActiveTop,
ActiveTopRight,
ActiveRight,
ActiveBottomRight,
ActiveBottom,
ActiveBottomLeft,
ActiveLeft,
ActiveTopLeft,
ACTIVE_BORDER_COUNT,
ActiveNone
ActiveNone = 0,
ActiveLeft = 1,
ActiveRight = 2,
ActiveTop = 4,
ActiveBottom = 8,
ActiveTopLeft = ActiveTop | ActiveLeft,
ActiveTopRight = ActiveTop | ActiveRight,
ActiveBottomLeft = ActiveBottom | ActiveLeft,
ActiveBottomRight = ActiveBottom | ActiveRight,
ACTIVE_BORDER_COUNT
};
enum ActiveMaximizingMode

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

Loading…
Cancel
Save