Skip to content

Commit a77295f

Browse files
committed
fix wayland resize issue and better wayland check method
1 parent ae741d8 commit a77295f

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

src/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "tools.h"
1414

15+
bool is_wayland;
1516
extern void mainWindowInit();
1617
int history;
1718

@@ -29,6 +30,7 @@ int main(int argc, char *argv[]) {
2930
p2.execute("gsettings", args2);
3031
#endif
3132

33+
is_wayland = (getenv("WAYLAND_DISPLAY") != NULL);
3234
// gnome wayland fullscreen compositor is buggy.
3335
// Force prefer Xwayland for fix this issue.
3436
bool force_xwayland = false;
@@ -39,6 +41,7 @@ int main(int argc, char *argv[]) {
3941
// Force use X11 or Xwayland
4042
if(get_bool("xwayland") || force_xwayland){
4143
setenv("QT_QPA_PLATFORM", "xcb;wayland",1);
44+
is_wayland = false;
4245
}
4346
//Force ignore system dpi
4447
setenv("QT_AUTO_SCREEN_SCALE_FACTOR", "0", 1);

src/tools.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extern QWidget *bgMenu;
6262

6363
extern float scale;
6464
extern int history;
65+
extern bool is_wayland;
6566

6667
extern QSlider *scrollHSlider;
6768
extern QSlider *scrollVSlider;

src/tools/mainWindow.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,22 @@ class MainWindow : public QMainWindow {
123123
floatingWidget->new_y = get_int("cur-y");
124124
// tool is not set under wayland
125125
if(floatingWidget != nullptr) {
126-
if(tool != nullptr){
126+
if(!is_wayland){
127127
tool->resize(floatingWidget->geometry().width(), floatingWidget->geometry().height());
128128
}
129-
if(tool2 != nullptr){
129+
if(!is_wayland){
130130
tool2->resize(floatingSettings->geometry().width(), floatingSettings->geometry().height());
131131
}
132132
drawing->update();
133133
}
134+
floatingWidget->moveAction();
134135
// Call the base class implementation
135136
QWidget::resizeEvent(event);
136-
floatingWidget->moveAction();
137137
}
138138
void changeEvent(QEvent *event) override {
139139
// Call the base class implementation
140140
QMainWindow::changeEvent(event);
141-
if(tool != nullptr){
141+
if(!is_wayland){
142142
if (event->type() == QEvent::WindowStateChange) {
143143
tool2->hide();
144144
if (isMinimized()) {
@@ -162,7 +162,7 @@ static bool hideState = true;
162162
void setupTools(){
163163
#ifndef ETAP19
164164
// detect x11
165-
if(!getenv("WAYLAND_DISPLAY")){
165+
if(!is_wayland){
166166
// main toolbar
167167
tool = new QMainWindow();
168168
tool->setWindowFlags(Qt::WindowStaysOnTopHint
@@ -247,7 +247,7 @@ void setupTools(){
247247
QScreen *screen = QGuiApplication::primaryScreen();
248248
toolButtons[FULLSCREEN] = create_button(FULLSCREEN_EXIT, [=](){
249249
mainWidget->move(0,0);
250-
if ((tool != nullptr) && (tool2 != nullptr)){
250+
if (!is_wayland){
251251
tool->hide();
252252
tool2->hide();
253253
tool->show();

src/widgets/FloatingWidget.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ void FloatingWidget::setVertical(bool state) {
8080
if(state) {
8181
layout->addWidget(widgets[i], row, column);
8282
setFixedSize(width, height);
83-
if(tool != nullptr){
83+
if(!is_wayland){
8484
tool->setFixedSize(width, height);
8585
}
86-
} else {
86+
} else {
8787
layout->addWidget(widgets[i], column, row, Qt::AlignCenter);
8888
setFixedSize(height, width);
89-
if(tool != nullptr){
89+
if(!is_wayland){
9090
tool->setFixedSize(height, width);
9191
}
9292
}
@@ -95,14 +95,15 @@ void FloatingWidget::setVertical(bool state) {
9595

9696

9797
void FloatingWidget::moveAction(){
98+
debug("Move Action %d %d\n", new_x, new_y);
9899
if (new_x < 0) {
99100
new_x = 0;
100101
}if (new_y < 0) {
101102
new_y = 0;
102103
}
103104
int max_width = mainWindow->geometry().width();
104105
int max_height = mainWindow->geometry().height();
105-
if(tool2 != nullptr){
106+
if(!is_wayland){
106107
max_width = QGuiApplication::primaryScreen()->size().width();
107108
max_height = QGuiApplication::primaryScreen()->size().height();
108109
}
@@ -111,7 +112,7 @@ void FloatingWidget::moveAction(){
111112
}if (new_y > max_height - size().height()) {
112113
new_y = max_height - size().height();
113114
}
114-
if(tool != nullptr){
115+
if(!is_wayland){
115116
tool->move(new_x, new_y);
116117
} else {
117118
move(new_x, new_y);
@@ -125,7 +126,7 @@ void FloatingWidget::moveAction(){
125126
if (new_yy > max_height - floatingSettings->cur_height) {
126127
new_yy = max_height - floatingSettings->cur_height;
127128
}
128-
if(tool2 != nullptr){
129+
if(!is_wayland){
129130
tool2->move(new_xx, new_yy);
130131
} else {
131132
floatingSettings->move(new_xx, new_yy);

0 commit comments

Comments
 (0)