From 0e4eb40d8e648d822e87ff74b1292a1dbf264892 Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Wed, 17 May 2023 11:34:58 +0200 Subject: Add window.c and window.h --- src/window.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/window.c (limited to 'src/window.c') 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 +#include +#include +#include +#include +#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); + } +} -- cgit v1.2.3