Add NeoUI 240x320 UI SDK, migrate all GUI plugins, add Yabasic FFI wrapper and fix camera rotation
This commit is contained in:
1 parent
1f9138f0c6
commit
c137feee0e
59 files changed
+5932
-2128
No files matched your search
+16
-68
@@ -675,51 +675,25 @@ static int xdrawer_run_main(int argc, char** argv) {
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
|
||||
Display* dpy = XOpenDisplay(nullptr);
|
||||
if (!dpy) {
|
||||
bananarchy::NeoWindow neo;
|
||||
if (!neo.create("xdrawer", "XDrawer", "XDrawer", kWinX, kWinY, kWinWidth,
|
||||
kWinHeight, true)) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(dpy);
|
||||
Window root = RootWindow(dpy, screen);
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa{};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = 0x222222;
|
||||
swa.border_pixel = 0xf4d03f;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
|
||||
StructureNotifyMask | VisibilityChangeMask;
|
||||
|
||||
Window win = XCreateWindow(
|
||||
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent, visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
|
||||
|
||||
XClassHint ch{};
|
||||
char resName[] = "xdrawer";
|
||||
char resClass[] = "XDrawer";
|
||||
ch.res_name = resName;
|
||||
ch.res_class = resClass;
|
||||
XSetClassHint(dpy, win, &ch);
|
||||
XStoreName(dpy, win, "XDrawer");
|
||||
|
||||
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight, DefaultDepth(dpy, screen));
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
PangoFontMap* fontMap = pango_xft_get_font_map(dpy, screen);
|
||||
PangoContext* pangoCtx = pango_font_map_create_context(fontMap);
|
||||
PangoLayout* layoutMain = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutIcon = pango_layout_new(pangoCtx);
|
||||
PangoLayout* layoutSmall = pango_layout_new(pangoCtx);
|
||||
|
||||
bananarchy::PluginTheme theme;
|
||||
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
|
||||
nullptr, win);
|
||||
Display* dpy = neo.dpy;
|
||||
int screen = neo.screen;
|
||||
Visual* visual = neo.visual;
|
||||
Colormap cmap = neo.cmap;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
PangoLayout* layoutMain = neo.layoutMain;
|
||||
PangoLayout* layoutIcon = neo.layoutIcon;
|
||||
PangoLayout* layoutSmall = neo.layoutSmall;
|
||||
bananarchy::PluginTheme& theme = neo.theme;
|
||||
XftColor& colWhite = theme.colWhite;
|
||||
XftColor& colLight = theme.colLight;
|
||||
XftColor& colMuted = theme.colMuted;
|
||||
@@ -735,27 +709,11 @@ static int xdrawer_run_main(int argc, char** argv) {
|
||||
|
||||
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
|
||||
const std::string& text, int maxW = -1) {
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
if (maxW > 0) {
|
||||
pango_layout_set_width(layout, maxW * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
} else {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
}
|
||||
PangoRectangle ink{}, logical{};
|
||||
pango_layout_get_pixel_extents(layout, &ink, &logical);
|
||||
int ty = y + (h - logical.height) / 2;
|
||||
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
|
||||
ty * PANGO_SCALE);
|
||||
neo.drawPango(layout, color, x, y, h, text, maxW);
|
||||
};
|
||||
|
||||
auto pangoWidth = [&](PangoLayout* layout, const std::string& text) -> int {
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
PangoRectangle ink{}, logical{};
|
||||
pango_layout_get_pixel_extents(layout, &ink, &logical);
|
||||
return logical.width;
|
||||
return neo.pangoWidth(layout, text);
|
||||
};
|
||||
|
||||
auto render = [&]() {
|
||||
@@ -1153,16 +1111,6 @@ static int xdrawer_run_main(int argc, char** argv) {
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
::unlink(fifoPath.c_str());
|
||||
::unlink(daemonPidPath.c_str());
|
||||
|
||||
g_object_unref(layoutSmall);
|
||||
g_object_unref(layoutIcon);
|
||||
g_object_unref(layoutMain);
|
||||
g_object_unref(pangoCtx);
|
||||
XftDrawDestroy(xftDraw);
|
||||
XFreeGC(dpy, gc);
|
||||
XFreePixmap(dpy, pix);
|
||||
XDestroyWindow(dpy, win);
|
||||
XCloseDisplay(dpy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user