PatchworkOS  3984a1d
A non-POSIX operating system.
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
2
3#include <errno.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <sys/defs.h>
8
9static image_t* image;
10
11static uint64_t procedure(window_t* win, element_t* elem, const event_t* event)
12{
13 UNUSED(win);
14
15 switch (event->type)
16 {
17 case EVENT_LIB_INIT:
18 {
19 }
20 break;
22 {
23 if (image == NULL)
24 {
25 printf("wall: image failed to load (%s)\n", strerror(errno));
26 break;
27 }
28
30
31 drawable_t draw;
32 element_draw_begin(elem, &draw);
33
34 point_t srcPoint = {.x = (image_width(image) - RECT_WIDTH(&rect)) / 2,
35 .y = (image_height(image) - RECT_HEIGHT(&rect)) / 2};
36 draw_image(&draw, image, &rect, &srcPoint);
37
38 element_draw_end(elem, &draw);
39 }
40 break;
41 }
42
43 return 0;
44}
45
46int main(void)
47{
48 fd_t klog = open("/dev/klog");
49 if (klog == ERR)
50 {
51 printf("taskbar: failed to open klog\n");
52 return EXIT_FAILURE;
53 }
55 {
56 printf("taskbar: failed to redirect stdout/stderr to klog\n");
57 close(klog);
58 return EXIT_FAILURE;
59 }
60 close(klog);
61
62 display_t* disp = display_new();
63 if (disp == NULL)
64 {
65 printf("wall: failed to create display (%s)\n", strerror(errno));
66 return EXIT_FAILURE;
67 }
68
69 if (display_unsubscribe(disp, EVENT_KBD) == ERR)
70 {
71 printf("wall: failed to unsubscribe from keyboard events (%s)\n", strerror(errno));
72 display_free(disp);
73 return EXIT_FAILURE;
74 }
76 {
77 printf("wall: failed to unsubscribe from mouse events (%s)\n", strerror(errno));
78 display_free(disp);
79 return EXIT_FAILURE;
80 }
81
82 rect_t rect;
83 display_get_screen(disp, &rect, 0);
84
87 if (image == NULL)
88 {
89 printf("wall: failed to load image '%s' (%s)\n", theme->wallpaper, strerror(errno));
90 display_free(disp);
91 return EXIT_FAILURE;
92 }
93
94 window_t* win = window_new(disp, "Wallpaper", &rect, SURFACE_WALL, WINDOW_NONE, procedure, NULL);
95 if (win == NULL)
96 {
97 printf("wall: failed to create window (%s)\n", strerror(errno));
99 display_free(disp);
100 return EXIT_FAILURE;
101 }
102
103 if (window_set_visible(win, true) == ERR)
104 {
105 printf("wall: failed to show window (%s)\n", strerror(errno));
106 window_free(win);
108 display_free(disp);
109 return EXIT_FAILURE;
110 }
111
112 event_t event = {0};
113 while (display_next(disp, &event, CLOCKS_NEVER) != ERR)
114 {
115 display_dispatch(disp, &event);
116 }
117
118 window_free(win);
120 display_free(disp);
121 return 0;
122}
static uint64_t procedure(window_t *win, element_t *elem, const event_t *event)
Definition main.c:46
int main(void)
Definition main.c:5
int64_t y
Definition main.c:153
static image_t * image
Definition main.c:6
#define CLOCKS_NEVER
Definition clock_t.h:16
uint64_t display_next(display_t *disp, event_t *event, clock_t timeout)
Retrieve the next event from the display connection.
Definition display.c:211
uint64_t display_unsubscribe(display_t *disp, event_type_t type)
Unsubscribe from events of a specific type.
Definition display.c:498
uint64_t display_dispatch(display_t *disp, const event_t *event)
Dispatch an event to the appropriate surface.
Definition display.c:410
uint64_t display_get_screen(display_t *disp, rect_t *rect, uint64_t index)
Get the rectangle of a screen.
Definition display.c:573
void display_free(display_t *disp)
Free a display connection.
Definition display.c:111
display_t * display_new(void)
Create a new display connection.
Definition display.c:46
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 EVENT_MOUSE
Definition event.h:84
#define EVENT_LIB_INIT
Definition event.h:98
#define EVENT_KBD
Definition event.h:83
#define EVENT_LIB_REDRAW
Definition event.h:100
@ SURFACE_WALL
Definition surface.h:38
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:704
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:313
void window_free(window_t *win)
Free a window.
Definition window.c:427
@ WINDOW_NONE
Definition window.h:45
#define errno
Error number variable.
Definition errno.h:27
#define UNUSED(x)
Mark a variable as unused.
Definition defs.h:100
fd_t dup2(fd_t oldFd, fd_t newFd)
System call for duplicating file descriptors, with a destination.
Definition dup2.c:8
fd_t open(const char *path)
System call for opening files.
Definition open.c:8
uint64_t close(fd_t fd)
System call for closing files.
Definition close.c:8
#define STDOUT_FILENO
Standard output file descriptor.
Definition io.h:35
#define STDERR_FILENO
Standard error file descriptor.
Definition io.h:36
#define NULL
Pointer error value.
Definition NULL.h:23
#define ERR
Integer error value.
Definition ERR.h:17
__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
static dentry_t * klog
Definition log.c:29
#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:3
#define EXIT_FAILURE
Definition stdlib.h:47
_PUBLIC char * strerror(int errnum)
Definition strerror.c:6
Opaque display structure.
Definition internal.h:68
Drawable structure.
Definition drawable.h:35
Opaque element structure.
Definition internal.h:23
Event structure.
Definition event.h:306
event_type_t type
Definition event.h:307
int64_t x
Definition point.h:13
Definition rect.h:13
Theme structure.
Definition theme.h:71
char wallpaper[MAX_PATH]
Definition theme.h:77
Opaque window structure.
Definition internal.h:44
static theme_t theme
Definition theme.c:12