Skip to content

Commit

Permalink
Let TaskBarShowAllWindows influence TaskBarTaskGrouping for issue #560.
Browse files Browse the repository at this point in the history
Improve truncation of titles for TaskBarTaskGrouping in issue #658.
  • Loading branch information
gijsbers committed Jun 17, 2022
1 parent 1d5b73c commit d11e207
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 22 deletions.
67 changes: 45 additions & 22 deletions src/atasks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,17 @@ int TaskButton::getOrder() const {
}

int TaskButton::getCount() const {
return grouping() ? fGroup.getCount() : bool(fActive);
int count = 0;
if (grouping()) {
if (taskBarShowAllWindows)
count = fGroup.getCount();
else
for (auto app : fGroup)
count += app->getShown();
} else {
count = (fActive != nullptr);
}
return count;
}

void TaskButton::addApp(TaskBarApp* tapp) {
Expand Down Expand Up @@ -234,6 +244,9 @@ void TaskButton::setShown(TaskBarApp* tapp, bool ashow) {
fActive = tapp;
gdraw = true;
}
else if (getShown()) {
gdraw = true;
}
fTaskPane->relayout();
if (visible() && gdraw)
repaint();
Expand Down Expand Up @@ -274,10 +287,7 @@ void TaskButton::configure(const YRect2& r) {
}

void TaskButton::repaint() {
if (width() > 1 && height() > 1) {
GraphicsBuffer(this).paint();
fRepainted = true;
}
fPaintTimer->setTimer(0L, this, true);
}

void TaskButton::handleExpose(const XExposeEvent& exp) {
Expand Down Expand Up @@ -542,7 +552,8 @@ void TaskButton::paint(Graphics& g, const YRect& r) {
x += 1;
}
g.setColor(fg);
g.drawStringEllipsis(textX + x, textY, str, wm);
g.drawStringEllipsis(textX + x, textY, str,
wm - max(0, x - 4));
}
}
}
Expand Down Expand Up @@ -617,14 +628,17 @@ YFont TaskButton::getActiveFont() {
void TaskButton::popupGroup() {
fMenu->setActionListener(this);
fMenu->removeAll();
IterGroup iter = fGroup.iterator();
while (++iter) {
YAction act(EAction(301 + 2 * iter.where()));
YMenuItem* item = fMenu->addItem(iter->getTitle(), -2, null, act);
if (iter == fActive) {
item->setChecked(true);
fActions.clear();
for (TaskBarApp* app : fGroup) {
if (taskBarShowAllWindows || app->getShown()) {
YAction act;
YMenuItem* item = fMenu->addItem(app->getTitle(), -2, null, act);
if (app == fActive) {
item->setChecked(true);
}
item->setIcon(app->getFrame()->getIcon());
fActions += PairType(act.ident(), app);
}
item->setIcon(iter->getFrame()->getIcon());
}
int x = 0, y = taskBarAtTop * height();
mapToGlobal(x, y);
Expand Down Expand Up @@ -690,16 +704,19 @@ void TaskButton::handleButton(const XButtonEvent& button) {
}

void TaskButton::actionPerformed(YAction action, unsigned modifiers) {
int index((action.ident() - 301) / 2);
if (inrange(index, 0, getCount() - 1)) {
if (fActive != fGroup[index]) {
TaskBarApp* old = fActive;
fActive = fGroup[index];
if (old)
old->repaint();
fActive->repaint();
for (const PairType& iter : fActions) {
if (iter.left == action.ident()) {
if (fActive != iter.right) {
TaskBarApp* old = fActive;
fActive = iter.right;
if (old)
old->repaint();
fActive->repaint();
}
if (fActive)
fActive->activate();
break;
}
fActive->activate();
}
}

Expand Down Expand Up @@ -777,6 +794,12 @@ bool TaskButton::handleTimer(YTimer* t) {
repaint();
return fFlashing;
}
if (t == fPaintTimer) {
if (width() > 1 && height() > 1 && getShown()) {
GraphicsBuffer(this).paint();
fRepainted = true;
}
}
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions src/atasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ class TaskButton:
int selected;
lazy<YTimer> fFlashTimer;
lazy<YTimer> fRaiseTimer;
lazy<YTimer> fPaintTimer;

typedef YArray<TaskBarApp*> GroupType;
typedef GroupType::IterType IterGroup;
GroupType fGroup;
lazy<YMenu> fMenu;
typedef pair<int, TaskBarApp*> PairType;
YArray<PairType> fActions;

virtual bool handleTimer(YTimer* t);
YFont getFont();
Expand Down

0 comments on commit d11e207

Please sign in to comment.