diff options
author | Marvin Borner | 2020-08-28 00:21:56 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-28 00:21:56 +0200 |
commit | e15051fd2d1d65af315ac4004256d5bc56a6dc67 (patch) | |
tree | 8d44262fb315d83e92c5840883948368cc169a7e | |
parent | 51bfb2559c158d285ae2bcb8338fa0f33e091fa3 (diff) |
Added window flags
-rw-r--r-- | apps/test.c | 2 | ||||
-rw-r--r-- | apps/wm.c | 27 | ||||
-rw-r--r-- | libgui/inc/gui.h | 9 |
3 files changed, 23 insertions, 15 deletions
diff --git a/apps/test.c b/apps/test.c index c542ca1..3077c04 100644 --- a/apps/test.c +++ b/apps/test.c @@ -11,7 +11,7 @@ int main() { print("[test loaded]\n"); - struct window *win = gui_new_window(); + struct window *win = gui_new_window(0); gui_fill(win, BG_COLOR); gui_border(win, FG_COLOR, 2); @@ -12,7 +12,7 @@ #include <sys.h> #include <vesa.h> -#define MOUSE_SLUGGISHNESS 4 // => Every nth move gets skipped +#define MOUSE_SKIP 4 // => Every nth move gets skipped static struct vbe *vbe; static struct window *direct; // Direct video memory window @@ -25,7 +25,7 @@ static struct list *windows; // List of all windows static int mouse_x = 0; static int mouse_y = 0; -static struct window *new_window(int x, int y, u16 width, u16 height) +static struct window *new_window(int x, int y, u16 width, u16 height, int flags) { struct window *win = malloc(sizeof(*win)); win->x = x; @@ -35,6 +35,7 @@ static struct window *new_window(int x, int y, u16 width, u16 height) win->bpp = vbe->bpp; win->pitch = win->width * (win->bpp >> 3); win->fb = malloc(height * win->pitch); + win->flags = flags; return win; } @@ -59,9 +60,10 @@ int main(int argc, char **argv) gui_init("/font/spleen-16x32.psfu"); windows = list_new(); - root = new_window(0, 0, vbe->width, vbe->height); - exchange = new_window(0, 0, vbe->width, vbe->height); - cursor = new_window(0, 0, 32, 32); + root = new_window(0, 0, vbe->width, vbe->height, WF_NO_FOCUS | WF_NO_DRAG | WF_NO_RESIZE); + exchange = + new_window(0, 0, vbe->width, vbe->height, WF_NO_FOCUS | WF_NO_DRAG | WF_NO_RESIZE); + cursor = new_window(0, 0, 32, 32, WF_NO_FOCUS | WF_NO_RESIZE); direct = malloc(sizeof(*direct)); memcpy(direct, root, sizeof(*direct)); direct->fb = vbe->fb; @@ -79,7 +81,7 @@ int main(int argc, char **argv) event_register(EVENT_MOUSE); struct message *msg; - int sluggish_ctr = 0; + int mouse_skip = 0; while (1) { if (!(msg = msg_receive())) { yield(); @@ -89,8 +91,8 @@ int main(int argc, char **argv) switch (msg->type) { case MSG_NEW_WINDOW: printf("New window for pid %d\n", msg->src); - struct window *win = - new_window(vbe->width / 2 - 250, vbe->height / 2 - 150, 500, 300); + struct window *win = new_window(vbe->width / 2 - 250, vbe->height / 2 - 150, + 500, 300, (int)msg->data); msg_send(msg->src, MSG_NEW_WINDOW, win); list_add(windows, win); focused = win; @@ -121,15 +123,16 @@ int main(int argc, char **argv) cursor->x = mouse_x; cursor->y = mouse_y; - if (event->but1 && mouse_y + (int)focused->height < vbe->height - 1 && - sluggish_ctr % MOUSE_SLUGGISHNESS == 0) { - sluggish_ctr = 0; + if (event->but1 && !(focused->flags & WF_NO_DRAG) && + mouse_y + (int)focused->height < vbe->height - 1 && + mouse_skip % MOUSE_SKIP == 0) { + mouse_skip = 0; focused->x = mouse_x; focused->y = mouse_y; redraw_all(); // TODO: Function to redraw one window } gui_win_on_win(direct, cursor, cursor->x, cursor->y); - sluggish_ctr++; + mouse_skip++; break; } default: diff --git a/libgui/inc/gui.h b/libgui/inc/gui.h index 308e3a1..ad089bd 100644 --- a/libgui/inc/gui.h +++ b/libgui/inc/gui.h @@ -15,6 +15,10 @@ #define FG_COLOR 0xffabb2bf #define BG_COLOR 0xff282c34 +#define WF_NO_FOCUS (1 << 0) +#define WF_NO_DRAG (1 << 1) +#define WF_NO_RESIZE (1 << 2) + // Generalized font struct struct font { char *chars; @@ -31,6 +35,7 @@ struct window { u8 *fb; u32 bpp; u32 pitch; + int flags; }; void gui_write_char(struct window *win, int x, int y, u32 c, char ch); @@ -48,7 +53,7 @@ void gui_init(char *font_path); * Wrappers */ -#define gui_new_window() \ - (msg_send(2, MSG_NEW_WINDOW, NULL), (struct window *)msg_receive_loop()->data) +#define gui_new_window(flags) \ + (msg_send(2, MSG_NEW_WINDOW, flags), (struct window *)msg_receive_loop()->data) #define gui_redraw() (msg_send(2, MSG_REDRAW, NULL)) // TODO: Partial redraw (optimization) #endif |