From cd5290a0a81728a0c24ef3981d9b82ad7db50aa3 Mon Sep 17 00:00:00 2001 From: deuce <> Date: Tue, 14 Apr 2020 20:19:16 +0000 Subject: [PATCH] When an X11 window is force to a non-integer scale size (ie: maximized, etc), center the xim in the resulting window and fill the rest with black. --- src/conio/x_cio.c | 4 +++ src/conio/x_events.c | 66 ++++++++++++++++++++++++++++++++++---------- src/conio/x_events.h | 1 + 3 files changed, 56 insertions(+), 15 deletions(-) diff --git a/src/conio/x_cio.c b/src/conio/x_cio.c index f5da8af784..f274e12f7c 100644 --- a/src/conio/x_cio.c +++ b/src/conio/x_cio.c @@ -418,6 +418,10 @@ int x_init(void) xp_dlclose(dl); return(-1); } + if((x11.XSetForeground=xp_dlsym(dl,XSetForeground))==NULL) { + xp_dlclose(dl); + return(-1); + } if(sem_init(&pastebuf_set, 0, 0)) { xp_dlclose(dl); diff --git a/src/conio/x_events.c b/src/conio/x_events.c index 03ee8a5648..7733e73382 100644 --- a/src/conio/x_events.c +++ b/src/conio/x_events.c @@ -238,8 +238,8 @@ my_fls(unsigned long mask) /* Get a connection to the X server and create the window. */ static int init_window() { - XGCValues gcv; - int i; + XGCValues gcv; + int i; XWMHints *wmhints; XClassHint *classhints; int ret; @@ -313,17 +313,16 @@ static int init_window() WM_DELETE_WINDOW = x11.XInternAtom(dpy, "WM_DELETE_WINDOW", False); gcv.function = GXcopy; - gcv.foreground = white; - gcv.background = black; + gcv.foreground = black | 0xff000000; + gcv.background = white; gcv.graphics_exposures = False; - gc=x11.XCreateGC(dpy, win, GCFunction | GCForeground | GCBackground | GCGraphicsExposures, &gcv); - x11.XSelectInput(dpy, win, KeyReleaseMask | KeyPressMask | + x11.XSelectInput(dpy, win, KeyReleaseMask | KeyPressMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask); - x11.XStoreName(dpy, win, "SyncConsole"); + x11.XStoreName(dpy, win, "SyncConsole"); x11.XSetWMProtocols(dpy, win, &WM_DELETE_WINDOW, 1); return(0); @@ -434,7 +433,7 @@ static int video_init() static void local_draw_rect(struct rectlist *rect) { - int x,y,xscale,yscale; + int x,y,xscale,yscale,xoff=0,yoff=0; unsigned int r, g, b; unsigned long pixel; int cleft = rect->rect.width; @@ -445,6 +444,14 @@ static void local_draw_rect(struct rectlist *rect) if (bitmap_width != cleft || bitmap_height != ctop) return; + + xoff = (x11_window_width - xim->width) / 2; + if (xoff < 0) + xoff = 0; + yoff = (x11_window_height - xim->height) / 2; + if (yoff < 0) + yoff = 0; + /* TODO: Translate into local colour depth */ for(y=0;y<rect->rect.height;y++) { idx = y*rect->rect.width; @@ -497,7 +504,7 @@ static void local_draw_rect(struct rectlist *rect) } /* This line was changed */ if (last && (((y & 0x1f) == 0x1f) || (y == rect->rect.height-1)) && cright >= 0) { - x11.XPutImage(dpy,win,gc,xim,cleft*x_cvstat.scaling,ctop*x_cvstat.scaling*x_cvstat.vmultiplier,cleft*x_cvstat.scaling,ctop*x_cvstat.scaling*x_cvstat.vmultiplier,(cright-cleft+1)*x_cvstat.scaling,(cbottom-ctop+1)*x_cvstat.scaling*x_cvstat.vmultiplier); + x11.XPutImage(dpy, win, gc, xim, cleft*x_cvstat.scaling, ctop*x_cvstat.scaling*x_cvstat.vmultiplier, cleft*x_cvstat.scaling + xoff, ctop*x_cvstat.scaling*x_cvstat.vmultiplier + yoff, (cright-cleft+1)*x_cvstat.scaling, (cbottom-ctop+1)*x_cvstat.scaling*x_cvstat.vmultiplier); cleft = rect->rect.width; cright = cbottom = -1; ctop = rect->rect.height; @@ -505,7 +512,7 @@ static void local_draw_rect(struct rectlist *rect) } if (last == NULL) - x11.XPutImage(dpy,win,gc,xim,rect->rect.x*x_cvstat.scaling,rect->rect.y*x_cvstat.scaling*x_cvstat.vmultiplier,rect->rect.x*x_cvstat.scaling,rect->rect.y*x_cvstat.scaling*x_cvstat.vmultiplier,rect->rect.width*x_cvstat.scaling,rect->rect.height*x_cvstat.scaling*x_cvstat.vmultiplier); + x11.XPutImage(dpy, win, gc, xim, rect->rect.x*x_cvstat.scaling, rect->rect.y*x_cvstat.scaling*x_cvstat.vmultiplier, rect->rect.x*x_cvstat.scaling + xoff, rect->rect.y*x_cvstat.scaling*x_cvstat.vmultiplier + yoff, rect->rect.width*x_cvstat.scaling, rect->rect.height*x_cvstat.scaling*x_cvstat.vmultiplier); else bitmap_drv_free_rect(last); last = rect; @@ -553,12 +560,37 @@ static void handle_resize_event(int width, int height) static void expose_rect(int x, int y, int width, int height) { int sx,sy,ex,ey; + int xoff=0, yoff=0; + + xoff = (x11_window_width - xim->width) / 2; + if (xoff < 0) + xoff = 0; + yoff = (x11_window_height - xim->height) / 2; + if (yoff < 0) + yoff = 0; + + if (xoff > 0 || yoff > 0) { + if (x < xoff || y < yoff || x + width > xoff + xim->width || y + height > yoff + xim->height) { + x11.XFillRectangle(dpy, win, gc, 0, 0, x11_window_width, yoff); + x11.XFillRectangle(dpy, win, gc, 0, yoff, xoff, yoff + xim->height); + x11.XFillRectangle(dpy, win, gc, xoff+xim->width, yoff, x11_window_width, yoff + xim->height); + x11.XFillRectangle(dpy, win, gc, 0, yoff + xim->height, x11_window_width, x11_window_height); + } + } - sx=x/x_cvstat.scaling; - sy=y/(x_cvstat.scaling*x_cvstat.vmultiplier); - - ex=x+width-1; - ey=y+height-1; + sx=(x-xoff)/x_cvstat.scaling; + sy=(y-yoff)/(x_cvstat.scaling*x_cvstat.vmultiplier); + if (sx < 0) + sx = 0; + if (sy < 0) + sy = 0; + + ex=(x-xoff)+width-1; + ey=(y-yoff)+height-1; + if (ex < 0) + ex = 0; + if (ey < 0) + ey = 0; if((ex+1)%x_cvstat.scaling) { ex += x_cvstat.scaling-(ex%x_cvstat.scaling); } @@ -572,7 +604,11 @@ static void expose_rect(int x, int y, int width, int height) if (last) { bitmap_drv_free_rect(last); last = NULL; + bitmap_drv_request_some_pixels(sx, sy, ex-sx+1, ey-sy+1); } + // Do nothing... + if (sx == ex || sy == ey) + return; bitmap_drv_request_some_pixels(sx, sy, ex-sx+1, ey-sy+1); } diff --git a/src/conio/x_events.h b/src/conio/x_events.h index d2d23aaad3..7bfb2c81de 100644 --- a/src/conio/x_events.h +++ b/src/conio/x_events.h @@ -83,6 +83,7 @@ struct x11 { unsigned int class, Visual *visual, unsigned long valuemask, XSetWindowAttributes *attributes); Colormap (*XCreateColormap)(Display *display, Window w, Visual *visual, int alloc); XClassHint *(*XAllocClassHint)(void); + int (*XSetForeground)(Display *display, GC gc, unsigned long foreground); Atom utf8; Atom targets; }; -- GitLab