PatchworkOS
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
2#include <stdio.h>
3#include <stdlib.h>
4
5static image_t* image;
6
7static uint64_t procedure(window_t* win, element_t* elem, const event_t* event)
8{
9 (void)win; // Unused
10
11 switch (event->type)
12 {
13 case LEVENT_REDRAW:
14 {
16 point_t srcPoint = {0};
17
18 drawable_t draw;
19 element_draw_begin(elem, &draw);
20
21 draw_image(&draw, image, &rect, &srcPoint);
22 element_draw_end(elem, &draw);
23 }
24 break;
25 }
26
27 return 0;
28}
29
30int main(void)
31{
32 fd_t klog = open("/dev/klog");
33 if (klog == ERR)
34 {
35 printf("cursor: failed to open klog\n");
36 return EXIT_FAILURE;
37 }
39 {
40 printf("cursor: failed to redirect stdout/stderr to klog\n");
41 close(klog);
42 return EXIT_FAILURE;
43 }
44 close(klog);
45
46 display_t* disp = display_new();
47 if (disp == NULL)
48 {
49 printf("cursor: failed to create display\n");
50 return EXIT_FAILURE;
51 }
52
55 if (image == NULL)
56 {
57 printf("cursor: failed to load cursor image\n");
58 return EXIT_FAILURE;
59 }
60
65
66 window_t* win = window_new(disp, "Cursor", &rect, SURFACE_CURSOR, WINDOW_NONE, procedure, NULL);
67 if (win == NULL)
68 {
69 printf("cursor: failed to create window\n");
70 return EXIT_FAILURE;
71 }
72
73 if (window_set_visible(win, true) == ERR)
74 {
75 printf("cursor: failed to show window\n");
76 window_free(win);
77 display_free(disp);
78 return EXIT_FAILURE;
79 }
80
81 event_t event = {0};
82 while (display_next(disp, &event, CLOCKS_NEVER) != ERR)
83 {
84 display_dispatch(disp, &event);
85 }
86
87 window_free(win);
89 display_free(disp);
90 return 0;
91}
#define CLOCKS_NEVER
Definition clock_t.h:16
static rect_t screenRect
Definition compositor.c:10
uint64_t display_next(display_t *disp, event_t *event, clock_t timeout)
Retrieve the next event from the display connection.
Definition display.c:213
uint64_t display_dispatch(display_t *disp, const event_t *event)
Dispatch an event to the appropriate surface.
Definition display.c:440
uint64_t display_get_screen(display_t *disp, rect_t *rect, uint64_t index)
Get the rectangle of a screen.
Definition display.c:603
void display_free(display_t *disp)
Free a display connection.
Definition display.c:113
display_t * display_new(void)
Create a new display connection.
Definition display.c:36
void draw_image(drawable_t *draw, image_t *image, const rect_t *destRect, const point_t *srcPoint)
Draw an image,.
Definition drawable.c:545
void element_draw_end(element_t *elem, drawable_t *draw)
End drawing to an element.
Definition element.c:427
rect_t element_get_content_rect(element_t *elem)
Get the element's rectangle in local coordinates.
Definition element.c:213
void element_draw_begin(element_t *elem, drawable_t *draw)
Begin drawing to an element.
Definition element.c:411
#define LEVENT_REDRAW
Definition event.h:101
@ SURFACE_CURSOR
Definition surface.h:37
theme_t * theme_global_get(void)
Get the global theme.
Definition theme.c:97
uint64_t window_set_visible(window_t *win, bool isVisible)
Set the visibility of the window.
Definition window.c:692
window_t * window_new(display_t *disp, const char *name, const rect_t *rect, surface_type_t type, window_flags_t flags, procedure_t procedure, void *private)
Allocate and initialize a new window.
Definition window.c:301
void window_free(window_t *win)
Free a window.
Definition window.c:415
@ WINDOW_NONE
Definition window.h:45
fd_t dup2(fd_t oldFd, fd_t newFd)
System call for duplicating file descriptors, with a destination.
Definition dup2.c:9
fd_t open(const char *path)
System call for opening files.
Definition open.c:9
uint64_t close(fd_t fd)
System call for closing files.
Definition close.c:9
#define STDOUT_FILENO
Definition io.h:45
#define STDERR_FILENO
Definition io.h:46
#define NULL
Pointer error value.
Definition NULL.h:23
__UINT64_TYPE__ fd_t
A file descriptor.
Definition fd_t.h:12
void image_free(image_t *image)
Definition image.c:74
uint64_t image_height(image_t *image)
Definition image.c:99
uint64_t image_width(image_t *image)
Definition image.c:94
image_t * image_new(display_t *disp, const char *path)
Definition image.c:27
#define ERR
Definition main.c:44
int main()
Definition main.c:97
static uint64_t procedure(window_t *win, element_t *elem, const event_t *event)
Definition main.c:46
static image_t * image
Definition main.c:5
#define RECT_INIT_DIM(x, y, width, height)
Definition rect.h:32
#define RECT_HEIGHT(rect)
Definition rect.h:39
#define RECT_WIDTH(rect)
Definition rect.h:38
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
_PUBLIC int printf(const char *_RESTRICT format,...)
Definition printf.c:5
#define EXIT_FAILURE
Definition stdlib.h:47
Opaque display structure.
Definition internal.h:61
Drawable structure.
Definition drawable.h:35
Opaque element structure.
Definition internal.h:23
Event structure.
Definition event.h:271
event_type_t type
Definition event.h:272
Definition rect.h:13
Theme structure.
Definition theme.h:71
char cursorArrow[MAX_PATH]
Definition theme.h:79
Opaque window structure.
Definition internal.h:44
static theme_t theme
Definition theme.c:12
fd_t klog
Definition thrd_create.c:11