summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-10-23 17:49:31 +0200
committerAnton Kling <anton@kling.gg>2023-10-23 17:49:31 +0200
commit6382172ac01ef17913c54177e556706d6ae2ec7f (patch)
tree90b88b30bc7e6fb085ac2f24b34a859b0650ba4c
parent64485df0e87a24275f5bd1df139052a95cee924c (diff)
WindowServer: Draw a border around the active window
-rw-r--r--userland/windowserver/draw.c39
-rw-r--r--userland/windowserver/ws.c33
-rw-r--r--userland/windowserver/ws.h1
3 files changed, 50 insertions, 23 deletions
diff --git a/userland/windowserver/draw.c b/userland/windowserver/draw.c
index 5b3402a..cf3cd99 100644
--- a/userland/windowserver/draw.c
+++ b/userland/windowserver/draw.c
@@ -41,6 +41,25 @@ void draw_mouse(DISPLAY *disp, int mouse_x, int mouse_y) {
update_full_display(disp, mouse_x, mouse_y);
}
+void draw_line(DISPLAY *disp, int sx, int sy, int dx, int dy, uint32_t color) {
+ int x = sx;
+ int y = sy;
+ for (;;) {
+ // Bounds checking
+ if (y * WIDTH + x > HEIGHT * WIDTH)
+ break;
+
+ if (x >= dx - 1 && y >= dy - 1)
+ break;
+ uint32_t *ptr = disp->back_buffer + (BPP * y * WIDTH) + (x * BPP);
+ *ptr = color;
+ if (x < dx - 1)
+ x++;
+ if (y < dy - 1)
+ y++;
+ }
+}
+
void draw_window(DISPLAY *disp, const WINDOW *w) {
int x, y;
uint8_t border_size = disp->border_size;
@@ -50,6 +69,18 @@ void draw_window(DISPLAY *disp, const WINDOW *w) {
const int sy = w->sy;
x = px;
y = py;
+ // Draw a border around the current selected window
+ if (w == disp->active_window) {
+ // Top
+ draw_line(disp, px - 1, py - 1, px + sx + 1, py - 1, 0xFF00FF);
+ // Bottom
+ draw_line(disp, px - 1, py + sy, px + sx + 1, py + sy, 0xFF00FF);
+ // Left
+ draw_line(disp, px - 1, py - 1, px - 1, py + sy + 1, 0xFF00FF);
+ // Right
+ draw_line(disp, px + sx, py - 1, px + sx, py + sy + 1, 0xFF00FF);
+ }
+
for (int i = 0; i < sy; i++) {
if ((i + py) * WIDTH + px > HEIGHT * WIDTH)
break;
@@ -57,7 +88,6 @@ void draw_window(DISPLAY *disp, const WINDOW *w) {
if (i * sx > HEIGHT * WIDTH)
break;
uint32_t *bm = &w->bitmap_ptr[i * sx];
- // ((uint8_t *)w->bitmap_ptr) + BPP * ((i + py) * WIDTH) + px * BPP;
for (int j = 0; j < sx; j++) {
ptr[j] = bm[j];
}
@@ -75,12 +105,7 @@ void update_active_window(DISPLAY *disp) {
}
void update_full_display(DISPLAY *disp, int mouse_x, int mouse_y) {
- draw_wallpaper(disp); /*
- for (int i = 0; i < 100; i++) {
- if (!disp->windows[i])
- continue;
- draw_window(disp, disp->windows[i]);
- }*/
+ draw_wallpaper(disp);
update_active_window(disp);
update_display(disp);
}
diff --git a/userland/windowserver/ws.c b/userland/windowserver/ws.c
index 331d141..2211b00 100644
--- a/userland/windowserver/ws.c
+++ b/userland/windowserver/ws.c
@@ -16,7 +16,6 @@
#define WINDOW_SERVER_SOCKET "/windowserver"
WINDOW *windows[100];
-WINDOW *active_window;
int mouse_x = 0;
int mouse_y = 0;
@@ -84,7 +83,7 @@ void setup(void) {
main_display.border_size = 1;
main_display.border_color = 0xF;
- active_window = NULL;
+ main_display.active_window = NULL;
for (int i = 0; i < 100; i++) {
windows[i] = NULL;
}
@@ -143,7 +142,7 @@ void add_window(int fd) {
WINDOW *w = windows[i] = malloc(sizeof(WINDOW));
w->fd = window_socket;
w->bitmap_ptr = NULL;
- active_window = w;
+ main_display.active_window = w;
}
#define CLIENT_EVENT_CREATESCREEN 0
@@ -199,7 +198,7 @@ void send_to_window(struct KEY_EVENT ev) {
.type = 0,
.ev = ev,
};
- write(active_window->fd, &e, sizeof(e));
+ write(main_display.active_window->fd, &e, sizeof(e));
}
void clamp_screen_position(int *x, int *y) {
@@ -232,7 +231,7 @@ int windowserver_key_events(struct KEY_EVENT ev, int *redraw) {
assert(0);
}
}
- if (!active_window)
+ if (!main_display.active_window)
return 0;
int x = 0;
int y = 0;
@@ -251,9 +250,10 @@ int windowserver_key_events(struct KEY_EVENT ev, int *redraw) {
break;
}
if (x || y) {
- active_window->x += x;
- active_window->y += y;
- clamp_screen_position(&active_window->x, &active_window->y);
+ main_display.active_window->x += x;
+ main_display.active_window->y += y;
+ clamp_screen_position(&main_display.active_window->x,
+ &main_display.active_window->y);
*redraw = 1;
return 1;
}
@@ -278,7 +278,7 @@ void focus_window(int x, int y) {
WINDOW *w = windows[i];
if (w->x < x && x < w->x + w->sx) {
if (w->y < y && y < w->y + w->sy) {
- active_window = windows[i];
+ main_display.active_window = windows[i];
}
}
}
@@ -321,10 +321,11 @@ void parse_mouse_event(int fd) {
focus_window(mouse_x, mouse_y);
}
if (middle_button) {
- if (active_window) {
- active_window->x += xc;
- active_window->y -= yc;
- clamp_screen_position(&active_window->x, &active_window->y);
+ if (main_display.active_window) {
+ main_display.active_window->x += xc;
+ main_display.active_window->y -= yc;
+ clamp_screen_position(&main_display.active_window->x,
+ &main_display.active_window->y);
}
}
update_mouse();
@@ -341,7 +342,7 @@ void parse_keyboard_event(int fd) {
for (int i = 0; i < n; i++) {
if (windowserver_key_events(ev[i], &redraw))
continue;
- if (!active_window)
+ if (!main_display.active_window)
continue;
send_to_window(ev[i]);
}
@@ -366,10 +367,10 @@ WINDOW *get_window(int fd, int *index) {
void kill_window(int i) {
windows[i] = NULL;
update_full_display(&main_display, mouse_x, mouse_y);
- active_window = NULL;
+ main_display.active_window = NULL;
for (int i = 0; i < 100; i++) {
if (windows[i]) {
- active_window = windows[i];
+ main_display.active_window = windows[i];
break;
}
}
diff --git a/userland/windowserver/ws.h b/userland/windowserver/ws.h
index 80f4726..9236e01 100644
--- a/userland/windowserver/ws.h
+++ b/userland/windowserver/ws.h
@@ -23,6 +23,7 @@ typedef struct {
uint8_t border_size;
uint8_t border_color;
uint8_t wallpaper_color;
+ WINDOW *active_window;
WINDOW **windows;
} DISPLAY;
#endif