diff options
| -rw-r--r-- | ui.c | 53 |
1 files changed, 25 insertions, 28 deletions
@@ -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, |
