aboutsummaryrefslogtreecommitdiff
path: root/src/window.c
diff options
context:
space:
mode:
authorAlessandro Iezzi <aiezzi@alessandroiezzi.it>2023-05-17 11:34:58 +0200
committerAlessandro Iezzi <aiezzi@alessandroiezzi.it>2023-05-17 11:34:58 +0200
commit0e4eb40d8e648d822e87ff74b1292a1dbf264892 (patch)
tree18655d3201c1987758d6723ed8506960040386e0 /src/window.c
parenta261c738abf870a11e0323402157e6fb759c22da (diff)
downloadcherry-0e4eb40d8e648d822e87ff74b1292a1dbf264892.tar.gz
cherry-0e4eb40d8e648d822e87ff74b1292a1dbf264892.zip
Add window.c and window.h
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/window.c b/src/window.c
new file mode 100644
index 0000000..2b495b0
--- /dev/null
+++ b/src/window.c
@@ -0,0 +1,84 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include "application.h"
+#include "window.h"
+
+CherryWindow *
+cherry_window_new(void)
+{
+ CherryWindow *w = malloc(sizeof(*w));
+ w->title = NULL;
+ w->dimension = cherry_dimension_new();
+ w->x = 0;
+ w->y = 0;
+
+ CherryApplication *app = cherry_application_get_running_app();
+
+ int offset = 10;
+ int border_width = 5;
+ XSizeHints hints;
+ hints.x = w->x + offset;
+ hints.y = w->y + offset;
+ hints.width = w->dimension->width + offset;
+ hints.height = w->dimension->height + offset;
+ hints.flags = PPosition|PSize;
+
+ XSetWindowAttributes attributes;
+ attributes.background_pixel = XWhitePixel(app->display, app->screen);
+
+ w->window_handler = XCreateWindow(app->display,
+ XRootWindow(app->display, app->screen),
+ hints.x, hints.y,
+ hints.width, hints.height,
+ border_width,
+ app->depth,
+ InputOutput,
+ app->visual,
+ CWBackPixel,
+ &attributes);
+ char hello[] = "Hello from another World!";
+ XSetStandardProperties(app->display,
+ w->window_handler,
+ hello, hello,
+ None, NULL, 0,
+ &hints);
+
+ clist_add(&(app->windows), &w->window_handler, sizeof(w->window_handler));
+
+ return w;
+}
+
+void
+cherry_window_set_title(CherryWindow *w, char *title)
+{
+ w->title = strdup(title);
+}
+
+void
+cherry_window_set_dimension(CherryWindow *w, int width, int height)
+{
+ w->dimension->width = width;
+ w->dimension->height = height;
+}
+
+void
+cherry_window_set_position(CherryWindow *w, int x, int y)
+{
+ w->x = x;
+ w->y = y;
+}
+
+void
+cherry_window_set_visible(CherryWindow *w, int visible)
+{
+ CherryApplication *app = cherry_application_get_running_app();
+
+ if (visible) {
+ XMapRaised(app->display, w->window_handler);
+ }
+}