Skip to content

Commit

Permalink
Fix workspace buttons for right-to-left languages.
Browse files Browse the repository at this point in the history
  • Loading branch information
gijsbers committed Dec 24, 2023
1 parent 8e3daf9 commit 07eb300
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/aworkspaces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ void WorkspacesPane::createButtons() {
void WorkspacesPane::resize(unsigned width, unsigned height) {
bool save(fReconfiguring);
fReconfiguring = true;
setSize(width, height);
long limit = limitWidth(width);
setSize(unsigned(limit), height);
fReconfiguring = save;
Expand All @@ -264,6 +265,8 @@ void WorkspacesPane::resize(unsigned width, unsigned height) {
fMoved = min(0, fMoved + excess);
repositionButtons();
}
else if (rightToLeft && (fReconfiguring | fRepositioning) == false)
repositionButtons();
}

long WorkspacesPane::limitWidth(long paneWidth) {
Expand Down Expand Up @@ -418,15 +421,16 @@ void WorkspacesPane::updateButtons() {
int width = extent() - fMoved;
for (int i = count(), n = workspaceCount; i < n; ++i) {
WorkspaceButton* wk = create(i, height());
wk->setPosition(width + fMoved, 0);
int x = rightToLeft ? fButtons[0]->x() - wk->width() : width;
wk->setPosition(x + fMoved, 0);
width += wk->width();
if (wk->extent() > 0 && wk->x() < max(width, int(this->width())))
wk->show();
}

resize(width, height());
int limit = int(this->width());
if (fMoved + width < limit) {
if (fMoved + width < limit || rightToLeft) {
fMoved = limit - width;
repositionButtons();
}
Expand Down Expand Up @@ -516,8 +520,16 @@ void WorkspacesPane::setPressed(int ws, bool set) {
}
}

int WorkspacesPane::extent() const {
return 0 < count() ? max(last()->extent(), first()->extent()) : 0;
}

int WorkspacesPane::lowest() const {
return 0 < count() ? min(last()->x(), first()->x()) : 0;
}

bool WorkspacesPane::limited() const {
return 0 < count() && (last()->extent() - fButtons[0]->x()) > int(width());
return extent() - lowest() > int(width());
}

void WorkspacesPane::drag(int ws, int dx, bool start, bool end) {
Expand Down Expand Up @@ -692,7 +704,7 @@ void WorkspacesPane::repaintWorkspace(int ws) {
ws = manager->activeWorkspace();
}
if (inrange(ws, 0, count() - 1)) {
fButtons[ws]->setStale();
index(ws)->setStale();
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/aworkspaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ class WorkspacesPane:
int count() const { return fButtons.getCount(); }
IterType iterator() { return fButtons.iterator(); }
WorkspaceButton* last() const { return fButtons[count()-1]; }
int extent() const { return 0 < count() ? last()->extent() : 0; }
WorkspaceButton* first() const { return fButtons[0]; }
int extent() const;
int lowest() const;
bool limited() const;

WorkspaceButton* create(int workspace, unsigned height);
Expand Down

0 comments on commit 07eb300

Please sign in to comment.