Просмотр исходного кода

Allow eight windows and terminals

Johannes Zellner 2 недель назад
Родитель
Сommit
2cbe1f8778
5 измененных файлов с 92 добавлено и 9 удалено
  1. 12 0
      tty.c
  2. 2 1
      tty.h
  3. 63 6
      ucmd_wm.c
  4. 14 1
      wm.c
  5. 1 1
      wm_abi.h

+ 12 - 0
tty.c

@@ -61,6 +61,18 @@ int tty_valid(int id)
 	return t && t->used;
 }
 
+int tty_free_count(void)
+{
+	unsigned int i, n = 0;
+
+	if (!tty_init())
+		return 0;
+	for (i = 0; i < TTY_MAX; i++)
+		if (!tty_slot(i)->used)
+			n++;
+	return (int)n;
+}
+
 int tty_create(void)
 {
 	struct process *p = current_proc();

+ 2 - 1
tty.h

@@ -5,10 +5,11 @@
 #ifndef TTY_H
 #define TTY_H
 
-#define TTY_MAX 4
+#define TTY_MAX 8
 #define TTY_BUF 4096
 
 int  tty_create(void);                    /* owner = current process */
+int  tty_free_count(void);                /* unused terminal slots */
 void tty_close(int id);
 int  tty_write(int id, const char *buf, unsigned int len); /* 0/-1, blocks */
 int  tty_write_str(int id, const char *s);

+ 63 - 6
ucmd_wm.c

@@ -33,6 +33,30 @@ static unsigned int prev_buttons;
 static int full_redraw = 1;
 static unsigned int bar_kexec_busy, bar_kexec_progress, bar_kexec_total;
 static int bar_temp_c = -1;
+static char bar_msg[24];
+static unsigned int bar_msg_until;
+static int bar_msg_dirty;
+
+static void bar_notice(const char *msg)
+{
+	unsigned int i;
+
+	for (i = 0; msg[i] && i + 1 < sizeof(bar_msg); i++)
+		bar_msg[i] = msg[i];
+	bar_msg[i] = '\0';
+	bar_msg_until = u_ticks_ms() + 2000;
+	bar_msg_dirty = 1;
+}
+
+static int free_window_slot(void)
+{
+	unsigned int i;
+
+	for (i = 0; i < WM_MAX_WINDOWS; i++)
+		if (!wins[i].info.used)
+			return 1;
+	return 0;
+}
 
 static unsigned int rgb16(unsigned int r, unsigned int g, unsigned int b)
 {
@@ -111,6 +135,10 @@ static void draw_bar(void)
 		   WM_BTN_FILES_H, "Files");
 	bar_button(WM_BTN_MINES_X, WM_BTN_MINES_Y, WM_BTN_MINES_W,
 		   WM_BTN_MINES_H, "Mines");
+	if (bar_msg_until &&
+	    (int)(u_ticks_ms() - bar_msg_until) < 0)
+		usurf_text(&screen, (int)(WM_BTN_MINES_X + WM_BTN_MINES_W + 8),
+			   5, bar_msg, 0xFFD250u, 0, 0, fbw, WM_BAR_H);
 
 	/* Rainbow separator (same y as the kernel's old bar). */
 	for (x = 0; x < fbw; x++) {
@@ -340,6 +368,15 @@ static void do_update(struct wm_status *st)
 	static char last_dt[20];
 	int kexec_changed = (st->kexec_busy != bar_kexec_busy) ||
 		(st->kexec_busy && st->kexec_progress != bar_kexec_progress);
+	unsigned int msg_now = u_ticks_ms();
+
+	if (bar_msg_dirty ||
+	    (bar_msg_until && (int)(msg_now - bar_msg_until) >= 0)) {
+		bar_dirty = 1;
+		bar_msg_dirty = 0;
+		if (bar_msg_until && (int)(msg_now - bar_msg_until) >= 0)
+			bar_msg_until = 0;
+	}
 
 	bar_kexec_busy = st->kexec_busy;
 	bar_kexec_progress = st->kexec_progress;
@@ -505,6 +542,19 @@ static int spawn_app(const char *path)
 	return pid;
 }
 
+static void spawn_app_checked(const char *path)
+{
+	if (!free_window_slot()) {
+		bar_notice("window limit");
+		full_redraw = 1;
+		return;
+	}
+	if (spawn_app(path) < 0) {
+		bar_notice("spawn failed");
+		full_redraw = 1;
+	}
+}
+
 static void handle_mouse(struct wm_status *st)
 {
 	unsigned int buttons = st->mouse.buttons;
@@ -515,24 +565,31 @@ static void handle_mouse(struct wm_status *st)
 	if (down && !was) {
 		if (mx >= WM_BTN_X && my >= WM_BTN_Y &&
 		    mx < WM_BTN_X + WM_BTN_W && my < WM_BTN_Y + WM_BTN_H) {
-			u_wm_create_term();
-			full_redraw = 1;
+			if (!free_window_slot()) {
+				bar_notice("window limit");
+				full_redraw = 1;
+			} else if (u_wm_create_term() < 0) {
+				bar_notice("cannot start term");
+				full_redraw = 1;
+			} else {
+				full_redraw = 1;
+			}
 		} else if (mx >= WM_BTN_CLOCK_X && my >= WM_BTN_CLOCK_Y &&
 			   mx < WM_BTN_CLOCK_X + WM_BTN_CLOCK_W &&
 			   my < WM_BTN_CLOCK_Y + WM_BTN_CLOCK_H) {
-			spawn_app("/ramfs/bin/clock");
+			spawn_app_checked("/ramfs/bin/clock");
 		} else if (mx >= WM_BTN_COLORS_X && my >= WM_BTN_COLORS_Y &&
 			   mx < WM_BTN_COLORS_X + WM_BTN_COLORS_W &&
 			   my < WM_BTN_COLORS_Y + WM_BTN_COLORS_H) {
-			spawn_app("/ramfs/bin/colors");
+			spawn_app_checked("/ramfs/bin/colors");
 		} else if (mx >= WM_BTN_FILES_X && my >= WM_BTN_FILES_Y &&
 			   mx < WM_BTN_FILES_X + WM_BTN_FILES_W &&
 			   my < WM_BTN_FILES_Y + WM_BTN_FILES_H) {
-			spawn_app("/ramfs/bin/files");
+			spawn_app_checked("/ramfs/bin/files");
 		} else if (mx >= WM_BTN_MINES_X && my >= WM_BTN_MINES_Y &&
 			   mx < WM_BTN_MINES_X + WM_BTN_MINES_W &&
 			   my < WM_BTN_MINES_Y + WM_BTN_MINES_H) {
-			spawn_app("/ramfs/bin/mines");
+			spawn_app_checked("/ramfs/bin/mines");
 		} else {
 			int idx = window_at(mx, my);
 

+ 14 - 1
wm.c

@@ -21,6 +21,7 @@
 #include "sys_gfx.h"
 #include "thermal.h"
 #include "timer.h"
+#include "tty.h"
 #include "version.h"
 #include "vga.h"
 #include "vfs.h"
@@ -287,8 +288,10 @@ int wm_server_win_create(const struct win_create *in, struct win_info *out)
 	for (i = 0; i < MAX_WINDOWS; i++)
 		if (!windows[i].used)
 			break;
-	if (i == MAX_WINDOWS)
+	if (i == MAX_WINDOWS) {
+		serial_puts(SERIAL_COM1, "wm: win_create no window slot\n");
 		return -1;
+	}
 	w = &windows[i];
 	c = &w->canvas;
 	if (gfx_alloc(c, cw, ch) != 0)
@@ -1185,6 +1188,16 @@ int wm_spawn_terminal(void)
 	int pid;
 	unsigned int n;
 
+	/* Do not start a term that has nowhere to go: it would create a tty
+	 * and then exit at SYS_WIN_CREATE, which looks like a dead button. */
+	for (i = 0; i < MAX_WINDOWS; i++)
+		if (!windows[i].used)
+			break;
+	if (i == MAX_WINDOWS || tty_free_count() <= 0) {
+		serial_puts(SERIAL_COM1, "wm: no term slot (windows/free tty)\n");
+		return -1;
+	}
+
 	/* Preferred path: the ring-3 terminal owns a canvas window and creates
 	 * its own tty.  The in-kernel cell terminal below is only a fallback for
 	 * a pack without /ramfs/bin/term. */

+ 1 - 1
wm_abi.h

@@ -4,7 +4,7 @@
 #ifndef WM_ABI_H
 #define WM_ABI_H
 
-#define WM_MAX_WINDOWS 4
+#define WM_MAX_WINDOWS 8
 
 /* Shared chrome layout (the WM draws it, the kernel only stores geometry). */
 #define WM_BAR_H   30