Fix SSD2092 wake, fuel-gauge jump, XLibre rotation, media keys, and popup rendering
This commit is contained in:
1 parent
7f3b3c2c0c
commit
dbc0275979
43 files changed
+3388
-115
No files matched your search
+91
-16
@@ -35,6 +35,10 @@ struct gemui_app {
|
||||
Window root;
|
||||
Window win;
|
||||
Pixmap backbuf;
|
||||
cairo_surface_t *img_surf;
|
||||
cairo_t *img_cr;
|
||||
cairo_surface_t *xlib_surf;
|
||||
PangoLayout *pango_layout;
|
||||
GC gc;
|
||||
int bw;
|
||||
int bh;
|
||||
@@ -71,6 +75,7 @@ struct gemui_app {
|
||||
};
|
||||
|
||||
static int g_sig_pipe[2] = {-1, -1};
|
||||
static PangoLayout *g_active_layout = NULL;
|
||||
|
||||
static void gemui_sigusr1_handler(int sig) {
|
||||
(void)sig;
|
||||
@@ -292,7 +297,26 @@ void gemui_theme_reload(gemui_app_t *app) {
|
||||
|
||||
static void gemui_ensure_backbuf(gemui_app_t *app) {
|
||||
if (app->w <= 0 || app->h <= 0) return;
|
||||
if (app->backbuf && app->bw == app->w && app->bh == app->h) return;
|
||||
if (app->backbuf && app->img_cr && app->xlib_surf &&
|
||||
app->bw == app->w && app->bh == app->h) {
|
||||
return;
|
||||
}
|
||||
if (app->pango_layout) {
|
||||
g_object_unref(app->pango_layout);
|
||||
app->pango_layout = NULL;
|
||||
}
|
||||
if (app->img_cr) {
|
||||
cairo_destroy(app->img_cr);
|
||||
app->img_cr = NULL;
|
||||
}
|
||||
if (app->img_surf) {
|
||||
cairo_surface_destroy(app->img_surf);
|
||||
app->img_surf = NULL;
|
||||
}
|
||||
if (app->xlib_surf) {
|
||||
cairo_surface_destroy(app->xlib_surf);
|
||||
app->xlib_surf = NULL;
|
||||
}
|
||||
if (app->backbuf) {
|
||||
XFreePixmap(app->dpy, app->backbuf);
|
||||
app->backbuf = 0;
|
||||
@@ -300,8 +324,17 @@ static void gemui_ensure_backbuf(gemui_app_t *app) {
|
||||
app->backbuf = XCreatePixmap(app->dpy, app->win, (unsigned int)app->w,
|
||||
(unsigned int)app->h,
|
||||
(unsigned int)DefaultDepth(app->dpy, app->screen));
|
||||
app->xlib_surf = cairo_xlib_surface_create(app->dpy, app->backbuf,
|
||||
DefaultVisual(app->dpy, app->screen),
|
||||
app->w, app->h);
|
||||
app->img_surf = cairo_image_surface_create(CAIRO_FORMAT_RGB24, app->w, app->h);
|
||||
app->img_cr = cairo_create(app->img_surf);
|
||||
app->pango_layout = pango_cairo_create_layout(app->img_cr);
|
||||
app->bw = app->w;
|
||||
app->bh = app->h;
|
||||
if (app->backbuf) {
|
||||
XSetWindowBackgroundPixmap(app->dpy, app->win, app->backbuf);
|
||||
}
|
||||
}
|
||||
|
||||
static int gemui_ignore_xerror(Display *dpy, XErrorEvent *ev) {
|
||||
@@ -360,11 +393,16 @@ gemui_app_t *gemui_create(const char *res_name, const char *title,
|
||||
app->w = w;
|
||||
app->h = h;
|
||||
|
||||
int wx = fullscreen_override ? 0 : (sw - w) / 2;
|
||||
int wy = fullscreen_override ? 0 : (sh - h) / 2;
|
||||
if (wx < 0) wx = 0;
|
||||
if (wy < 0) wy = 0;
|
||||
|
||||
gemui_theme_reload(app);
|
||||
|
||||
XSetWindowAttributes swa;
|
||||
memset(&swa, 0, sizeof(swa));
|
||||
swa.background_pixel = BlackPixel(dpy, app->screen);
|
||||
swa.background_pixmap = None;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
|
||||
ButtonReleaseMask | PointerMotionMask |
|
||||
StructureNotifyMask | FocusChangeMask;
|
||||
@@ -372,9 +410,21 @@ gemui_app_t *gemui_create(const char *res_name, const char *title,
|
||||
swa.override_redirect = True;
|
||||
}
|
||||
|
||||
unsigned long mask = CWBackPixel | CWEventMask | (fullscreen_override ? CWOverrideRedirect : 0);
|
||||
app->win = XCreateWindow(dpy, app->root, 0, 0, (unsigned int)w, (unsigned int)h, 0,
|
||||
unsigned long mask = CWBackPixmap | CWEventMask | (fullscreen_override ? CWOverrideRedirect : 0);
|
||||
app->win = XCreateWindow(dpy, app->root, wx, wy, (unsigned int)w, (unsigned int)h, 0,
|
||||
CopyFromParent, InputOutput, CopyFromParent, mask, &swa);
|
||||
{
|
||||
XSizeHints *shints = XAllocSizeHints();
|
||||
if (shints) {
|
||||
shints->flags = PPosition | PSize;
|
||||
shints->x = wx;
|
||||
shints->y = wy;
|
||||
shints->width = w;
|
||||
shints->height = h;
|
||||
XSetWMNormalHints(dpy, app->win, shints);
|
||||
XFree(shints);
|
||||
}
|
||||
}
|
||||
{
|
||||
Cursor cur = XCreateFontCursor(dpy, XC_left_ptr);
|
||||
if (cur != None) {
|
||||
@@ -412,8 +462,9 @@ gemui_app_t *gemui_create(const char *res_name, const char *title,
|
||||
XNClientWindow, app->win, XNFocusWindow, app->win, NULL);
|
||||
}
|
||||
|
||||
XMapRaised(dpy, app->win);
|
||||
if (fullscreen_override) {
|
||||
XMapRaised(dpy, app->win);
|
||||
app->mapped = true;
|
||||
XMoveResizeWindow(dpy, app->win, 0, 0, (unsigned int)sw, (unsigned int)sh);
|
||||
gemui_save_prev_focus(app);
|
||||
XSetInputFocus(dpy, app->win, RevertToPointerRoot, CurrentTime);
|
||||
@@ -428,6 +479,10 @@ void gemui_destroy(gemui_app_t *app) {
|
||||
gemui_restore_prev_focus(app);
|
||||
if (app->xic) XDestroyIC(app->xic);
|
||||
if (app->xim) XCloseIM(app->xim);
|
||||
if (app->pango_layout) g_object_unref(app->pango_layout);
|
||||
if (app->img_cr) cairo_destroy(app->img_cr);
|
||||
if (app->img_surf) cairo_surface_destroy(app->img_surf);
|
||||
if (app->xlib_surf) cairo_surface_destroy(app->xlib_surf);
|
||||
if (app->backbuf) XFreePixmap(app->dpy, app->backbuf);
|
||||
if (app->gc) XFreeGC(app->dpy, app->gc);
|
||||
if (app->win) XDestroyWindow(app->dpy, app->win);
|
||||
@@ -518,13 +573,18 @@ void gemui_quit(gemui_app_t *app, int code) {
|
||||
|
||||
bool gemui_grab_input(gemui_app_t *app) {
|
||||
if (!app) return false;
|
||||
if (!app->mapped) {
|
||||
gemui_flush_draw(app);
|
||||
}
|
||||
bool ok_kbd = XGrabKeyboard(app->dpy, app->win, True, GrabModeAsync,
|
||||
GrabModeAsync, CurrentTime) == GrabSuccess;
|
||||
XGrabPointer(app->dpy, app->win, True,
|
||||
ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
||||
GrabModeAsync, GrabModeAsync, app->win, None, CurrentTime);
|
||||
gemui_save_prev_focus(app);
|
||||
XSetInputFocus(app->dpy, app->win, RevertToPointerRoot, CurrentTime);
|
||||
if (app->mapped) {
|
||||
XSetInputFocus(app->dpy, app->win, RevertToPointerRoot, CurrentTime);
|
||||
}
|
||||
XFlush(app->dpy);
|
||||
return ok_kbd;
|
||||
}
|
||||
@@ -563,23 +623,31 @@ const gemui_hit_t *gemui_hit_test(const gemui_app_t *app, int x, int y) {
|
||||
static void gemui_render_frame(gemui_app_t *app) {
|
||||
if (!app || !app->need_redraw || app->w <= 0 || app->h <= 0) return;
|
||||
gemui_ensure_backbuf(app);
|
||||
if (!app->backbuf) return;
|
||||
|
||||
cairo_surface_t *surf = cairo_xlib_surface_create(
|
||||
app->dpy, app->backbuf, DefaultVisual(app->dpy, app->screen), app->w, app->h);
|
||||
cairo_t *cr = cairo_create(surf);
|
||||
if (!app->backbuf || !app->img_cr || !app->xlib_surf) return;
|
||||
|
||||
cairo_t *cr = app->img_cr;
|
||||
g_active_layout = app->pango_layout;
|
||||
gemui_hits_clear(app);
|
||||
gemui_fill_rect(cr, (gemui_rect_t){0, 0, app->w, app->h}, app->theme.bg_main);
|
||||
if (app->handlers.on_draw) {
|
||||
app->handlers.on_draw(app, cr, app->w, app->h, app->userdata);
|
||||
}
|
||||
gemui_draw_toast(app, cr);
|
||||
g_active_layout = NULL;
|
||||
cairo_surface_flush(app->img_surf);
|
||||
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_flush(surf);
|
||||
cairo_surface_destroy(surf);
|
||||
cairo_t *xcr = cairo_create(app->xlib_surf);
|
||||
cairo_set_operator(xcr, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_set_source_surface(xcr, app->img_surf, 0, 0);
|
||||
cairo_paint(xcr);
|
||||
cairo_destroy(xcr);
|
||||
cairo_surface_flush(app->xlib_surf);
|
||||
|
||||
if (!app->mapped) {
|
||||
XSetWindowBackgroundPixmap(app->dpy, app->win, app->backbuf);
|
||||
XMapRaised(app->dpy, app->win);
|
||||
app->mapped = true;
|
||||
}
|
||||
XCopyArea(app->dpy, app->backbuf, app->win, app->gc, 0, 0,
|
||||
(unsigned int)app->w, (unsigned int)app->h, 0, 0);
|
||||
XFlush(app->dpy);
|
||||
@@ -658,6 +726,12 @@ static void gemui_handle_x_events(gemui_app_t *app) {
|
||||
}
|
||||
break;
|
||||
case MotionNotify:
|
||||
while (XPending(app->dpy) > 0) {
|
||||
XEvent pev;
|
||||
XPeekEvent(app->dpy, &pev);
|
||||
if (pev.type != MotionNotify || pev.xmotion.window != ev.xmotion.window) break;
|
||||
XNextEvent(app->dpy, &ev);
|
||||
}
|
||||
if (app->ptr_down && app->handlers.on_ptr) {
|
||||
app->handlers.on_ptr(app, GEMUI_PTR_MOVE, ev.xmotion.x, ev.xmotion.y,
|
||||
0, app->userdata);
|
||||
@@ -807,13 +881,14 @@ static int gemui_draw_pango(cairo_t *cr, const char *face, int px_size,
|
||||
gemui_rect_t r, const char *text, bool bold,
|
||||
int align, gemui_color_t c) {
|
||||
if (!text || !text[0] || r.w <= 4 || r.h <= 4) return 0;
|
||||
PangoLayout *layout = pango_cairo_create_layout(cr);
|
||||
PangoLayout *layout = g_active_layout ? g_active_layout : pango_cairo_create_layout(cr);
|
||||
char desc_str[160];
|
||||
snprintf(desc_str, sizeof(desc_str), "%s%s %dpx",
|
||||
face && face[0] ? face : "Fira Code",
|
||||
bold ? " Bold" : "",
|
||||
px_size > 8 ? px_size : 14);
|
||||
PangoFontDescription *desc = pango_font_description_from_string(desc_str);
|
||||
pango_layout_set_attributes(layout, NULL);
|
||||
pango_layout_set_font_description(layout, desc);
|
||||
pango_layout_set_width(layout, r.w * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
@@ -835,7 +910,7 @@ static int gemui_draw_pango(cairo_t *cr, const char *face, int px_size,
|
||||
pango_cairo_show_layout(cr, layout);
|
||||
|
||||
pango_font_description_free(desc);
|
||||
g_object_unref(layout);
|
||||
if (!g_active_layout) g_object_unref(layout);
|
||||
return tw;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user