aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-01-17 17:26:46 +0100
committerdec05eba <dec05eba@protonmail.com>2023-01-17 17:26:46 +0100
commitc6d09be0a56c7b96be48f074901a53d7f76c25cc (patch)
treee55f15f827cbf1d9cf523448cbcfabce5c2a8814
parentbb770991b2d688b247106e116c1ee222c6dbbe11 (diff)
Add option to set window background color
This window background color is different than window.clear(color) because this window color is the background color if the window itself, which means if there is a delay between creating the window and the first frame display then the window background color is black, but if window color is set then that color will be displayed instead. Normally you want to set the window background color to the same color as the color you use in window.clear(color).
-rw-r--r--TODO2
-rw-r--r--include/mgl/window/window.h1
-rw-r--r--src/window/window.c8
3 files changed, 9 insertions, 2 deletions
diff --git a/TODO b/TODO
index 859b9db..86d4bce 100644
--- a/TODO
+++ b/TODO
@@ -8,4 +8,4 @@ Only render one glyph for missing symbols.\
High precision mouse wheel event by using xi2, which also allows us to get which scroll wheel was used and scrolling in y direction.\
Use XPresent (PresentNotifyMSC, glSwapBuffers, wait for PresentCompleteNotify before doing presentNotifyMsc and glSwapBuffers again), see https://invent.kde.org/plasma/kwin/-/issues/27. This doesn't work on nvidia because nvidia never sends the PresentCompleteNotify event.
Support drag and drop.\
-Pasting image into mgl doesn't always work. For example when using wayland + sway. Only 64k are copied (even when chunk size is set to 20kb instead of 32kb. One workaround would be to set chunk size and 1024 to 0x1ffffffff). \ No newline at end of file
+Use _NET_WM_SYNC_REQUEST.
diff --git a/include/mgl/window/window.h b/include/mgl/window/window.h
index 27926b2..cb5a2eb 100644
--- a/include/mgl/window/window.h
+++ b/include/mgl/window/window.h
@@ -54,6 +54,7 @@ typedef struct {
bool hidden; /* false by default */
bool override_redirect; /* false by default */
bool support_alpha; /* support alpha for the window, false by default */
+ mgl_color background_color; /* default: black */
} mgl_window_create_params;
typedef enum {
diff --git a/src/window/window.c b/src/window/window.c
index 958adab..101fb42 100644
--- a/src/window/window.c
+++ b/src/window/window.c
@@ -282,6 +282,12 @@ static void mgl_window_on_resize(mgl_window *self, int width, int height) {
mgl_window_set_scissor(self, &(mgl_scissor){ .position = { 0, 0 }, .size = self->size });
}
+static unsigned long mgl_color_to_x11_pixel(mgl_color color) {
+ if(color.a == 0)
+ return 0;
+ return (color.r << 16) | (color.g << 8) | color.b;
+}
+
static int mgl_window_init(mgl_window *self, const char *title, const mgl_window_create_params *params, Window existing_window) {
self->window = 0;
self->context = NULL;
@@ -336,7 +342,7 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window
XSetWindowAttributes window_attr;
window_attr.override_redirect = params ? params->override_redirect : false;
window_attr.colormap = x11_context->color_map;
- window_attr.background_pixel = 0;
+ window_attr.background_pixel = mgl_color_to_x11_pixel(params ? params->background_color : (mgl_color){ .r = 0, .g = 0, .b = 0, .a = 0 });
window_attr.border_pixel = 0;
window_attr.bit_gravity = NorthWestGravity;
window_attr.event_mask =