diff options
author | 2023-05-17 11:34:58 +0200 | |
---|---|---|
committer | 2023-05-17 11:34:58 +0200 | |
commit | 0e4eb40d8e648d822e87ff74b1292a1dbf264892 (patch) | |
tree | 18655d3201c1987758d6723ed8506960040386e0 | |
parent | a261c738abf870a11e0323402157e6fb759c22da (diff) | |
download | cherry-0e4eb40d8e648d822e87ff74b1292a1dbf264892.tar.gz cherry-0e4eb40d8e648d822e87ff74b1292a1dbf264892.zip |
Add window.c and window.h
-rw-r--r-- | src/window.c | 84 | ||||
-rw-r--r-- | src/window.h | 24 |
2 files changed, 108 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); + } +} diff --git a/src/window.h b/src/window.h new file mode 100644 index 0000000..9f3962c --- /dev/null +++ b/src/window.h @@ -0,0 +1,24 @@ +/* See LICENSE file for copyright and license details. */ + +#ifndef __CHERRY_WINDOW_H__ +#define __CHERRY_WINDOW_H__ + +#include "dimension.h" + +typedef struct { + char *title; + CherryDimension *dimension; + int x, y; + int visible; + + /* Xlib stuff */ + Window window_handler; +} CherryWindow; + +CherryWindow *cherry_window_new(void); +void cherry_window_set_title(CherryWindow *, char *); +void cherry_window_set_dimension(CherryWindow *, int, int); +void cherry_window_set_position(CherryWindow *, int, int); +void cherry_window_set_visible(CherryWindow *, int); + +#endif /* __CHERRY_WINDOW_H__ */ |