summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2026-01-30 18:35:19 -0500
committerWormHeamer2026-01-30 18:35:19 -0500
commit3d20aa3380a8c85fdb7bcd3cc45e3587b4f62fb6 (patch)
tree9e7fa38be37fc0644151cb7ccc37c91c88706e68
parent0eedaf40d33940b2667027be619b02c210328021 (diff)
create window with correct size & position instead of XMoveResize
-rw-r--r--ui.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/ui.c b/ui.c
index 3e06b91..d30cc88 100644
--- a/ui.c
+++ b/ui.c
@@ -118,9 +118,31 @@ ui_init(int argc, char **argv, UiOpts opt)
int scr_width = XWidthOfScreen(ScreenOfDisplay(dsp, scr));
int scr_height = XHeightOfScreen(ScreenOfDisplay(dsp, scr));
+ /* TODO: error checking */
+ ft_opt = ft_load("-*-new century schoolbook-medium-r-*-*-24-*-*-*-*-*-*-*");
+ ft_inp = ft_load("-*-new century schoolbook-medium-i-*-*-24-*-*-*-*-*-*-*");
+
+ if (!ft_opt) ft_opt = ft_load("fixed");
+ if (!ft_inp) ft_inp = ft_load("fixed");
+
+ /* calculate window size */
+
+ int w = 0;
+ for (int i = 0; i < opt.n; i++) {
+ int ow = ft_width(ft_opt, opt.v[i].s, opt.v[i].n);
+ if (ow > w) w = ow;
+ }
+
+ int h = 24 * (opt.n + 1);
+ int margin = 64;
+ if (w > scr_width - 2*margin) w = scr_width - 2*margin;
+ if (h > scr_height - 2*margin) h = scr_height - 2*margin;
+
szhint = (XSizeHints) { 0 };
- szhint.width = 350;
- szhint.height = 250;
+ szhint.x = (scr_width - w - 32) / 2;
+ szhint.y = (scr_height - h - 32) / 2;
+ szhint.width = w + 32;
+ szhint.height = h + 32;
szhint.flags = PSize;
win = XCreateWindow(
@@ -136,6 +158,7 @@ ui_init(int argc, char **argv, UiOpts opt)
.background_pixel = bg,
.border_pixel = fg,
.bit_gravity = NorthWestGravity,
+ .win_gravity = CenterGravity,
.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask
| ExposureMask | VisibilityChangeMask | StructureNotifyMask
| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask,
@@ -150,35 +173,9 @@ ui_init(int argc, char **argv, UiOpts opt)
XSetBackground(dsp, gc, bg);
XSetForeground(dsp, gc, fg);
- //XSelectInput(dsp, win, KeyPressMask | ExposureMask);
-
wm_delete_window = XInternAtom(dsp, "WM_DELETE_WINDOW", False);
XSetWMProtocols(dsp, win, &wm_delete_window, 1);
-
- /* TODO: error checking */
- ft_opt = ft_load("-*-new century schoolbook-medium-r-*-*-24-*-*-*-*-*-*-*");
- ft_inp = ft_load("-*-new century schoolbook-medium-i-*-*-24-*-*-*-*-*-*-*");
-
- if (!ft_opt) ft_opt = ft_load("fixed");
- if (!ft_inp) ft_inp = ft_load("fixed");
-
- int w = 0;
- for (int i = 0; i < opt.n; i++) {
- int ow = ft_width(ft_opt, opt.v[i].s, opt.v[i].n);
- if (ow > w) w = ow;
- }
-
- int h = 24 * (opt.n + 1);
- int margin = 64;
- if (w > scr_width - 2*margin) w = scr_width - 2*margin;
- if (h > scr_height - 2*margin) h = scr_height - 2*margin;
-
- XResizeWindow(dsp, win, w + 32, h + 32);
XSetTransientForHint(dsp, win, DefaultRootWindow(dsp));
- XMoveWindow(dsp, win,
- (scr_width - w - 32) / 2,
- (scr_height - h - 32) / 2
- );
im = XOpenIM(dsp, NULL, NULL, NULL);
ic = XCreateIC(im,