CtrlCore: gtk: More window geometry fixes

This commit is contained in:
Mirek Fidler 2026-01-16 09:11:40 +01:00
parent 15f1c0cc98
commit d8e4b34c93
5 changed files with 36 additions and 25 deletions

View file

@ -87,9 +87,10 @@ void Ctrl::Create(Ctrl *owner, bool popup)
bool custom_bar = tw && tw->custom_bar;
static bool need_csd = IsWayland() && GetEnv("XDG_SESSION_DESKTOP") != "KDE";
top->csd = !popup && (need_csd || custom_bar);
#ifdef flagFORCE_CSD // Force using client side decorations even when server side is available
top->csd = !popup;
#ifndef flagFORCE_CSD // Force using client side decorations even when server side is available
if(tw && tw->force_csd)
#endif
top->csd = !popup;
if(top->csd) {
ONCELOCK {
UpdateWindowDecorationsGeometry();

View file

@ -21,7 +21,9 @@ void TopWindow::SyncSizeHints()
if(top->csd) {
mcx += csd_border.left + csd_border.right;
mcy += csd_border.top + csd_border.bottom;
if(!custom_bar)
if(custom_bar_frame)
mcy += GetCustomTitleBarMetrics().height;
else
mcy += csd_std_header_cy;
}

View file

@ -24,7 +24,12 @@
CustomBarIcon minicon, maxicon, closeicon;
Color custom_titlebar_bk = SColorFace();
int custom_titlebar_cy = -1;
bool force_csd = false;
public:
void Force_csd_() { force_csd = true; } // this is for testing...
private:
enum { FULLSCREEN = 99 };
void CenterRect(Ctrl *owner);

View file

@ -219,18 +219,6 @@ void Ctrl::WndRectsSync() const
width = gtk_widget_get_allocated_width(w);
height = gtk_widget_get_allocated_height(w);
/* TODO: Remove?
if(IsWayland()) {
if(top && utop->csd) {
gdk_window_get_origin(gtk_widget_get_window(w), &x, &y);
width = gtk_widget_get_allocated_width(w);
height = gtk_widget_get_allocated_height(w);
}
else
gdk_window_get_geometry(gdk(), &x, &y, &width, &height);
}
else
*/
if(top && utop->csd) {
gdk_window_get_root_origin(gdk(), &x, &y);
int x1, y1;
@ -584,10 +572,15 @@ void Ctrl::WndSetPos(const Rect& rect)
TopWindow *tw = dynamic_cast<TopWindow *>(this);
if(tw)
tw->SyncSizeHints();
if(top && utop->csd) {
int top = csd_border.top;
if(!tw || !tw->custom_bar)
top += csd_std_header_cy;
if(tw) {
if(tw->custom_bar_frame)
top += tw->GetCustomTitleBarMetrics().height;
else
top += csd_std_header_cy;
}
gdk_window_move_resize(gdk(), LSC(rect.left - csd_border.left), LSC(rect.top - top),
LSCH(rect.GetWidth() + csd_border.left + csd_border.right),
LSCH(rect.GetHeight() + top + csd_border.bottom));
@ -596,6 +589,7 @@ void Ctrl::WndSetPos(const Rect& rect)
Rect m(0, 0, 0, 0);
if(tw)
m = frameMargins;
gdk_window_move_resize(gdk(), LSC(rect.left - m.left), LSC(rect.top - m.top),
LSCH(rect.GetWidth()), LSCH(rect.GetHeight()));
}

View file

@ -12,9 +12,10 @@ struct App : public TopWindow
DrawFrame(w, 0, 0, 500, 500, Black());
DrawFrame(w, 0, 0, 400, 400, Black());
DrawFrame(w, 0, 0, 600, 600, Black());
w.DrawText(10, 10, AsString(GetScreenRect()));
w.DrawText(10, 50, AsString(GetRect()));
w.DrawText(10, 90, AsString(GetMousePos()));
w.DrawText(10, 10, AsString(GetScreenView()));
w.DrawText(10, 50, AsString(GetScreenRect()));
w.DrawText(10, 90, AsString(GetRect()));
w.DrawText(10, 130, AsString(GetMousePos()));
}
void MouseMove(Point p, dword keyflags) override {
@ -37,7 +38,7 @@ struct App : public TopWindow
App()
{
SetRect(10, 100, 500, 500);
SetRect(100, 200, 500, 500);
Sizeable().Zoomable();
Add(dl.LeftPos(10, 101).BottomPos(0));
@ -57,7 +58,7 @@ struct App2 : App {
Label title;
App2() {
SetRect(500, 100, 500, 500);
SetRect(700, 200, 500, 500);
Ctrl *tb = CustomTitleBar(SYellow(), GetStdFontCy() + DPI(4));
if(tb)
*tb << title.SizePos();
@ -69,10 +70,18 @@ struct App2 : App {
GUI_APP_MAIN
{
App app;
App app, app_csd;
App2 app2;
app.Title("SSD");
app_csd.Title("CSD");
app_csd.Force_csd_();
app_csd.SetRect(1300, 200, 500, 500);
app.OpenMain();
app_csd.OpenMain();
app2.OpenMain();
Ctrl::EventLoop();
app.Run();
}