Introduced CTK_CONF_WINDOWS.

If it is set the behaviour is (supposed to be) as before. Otherwise ctk supports just one window in fullscreen mode: No windows, no borders, no menu, no dialogs, no desktop.
The ctk draw interface stays stable but obviously further code savings are possible by making ctk draw implementations CTK_CONF_WINDOWS aware.
Currently the fullscreen mode doesn't work with mouse support - this is supposed to come later...
This commit is contained in:
oliverschmidt 2007-12-14 23:34:19 +00:00
parent c028df7ecf
commit 2da3a926a2
2 changed files with 111 additions and 35 deletions

View File

@ -44,7 +44,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: ctk.c,v 1.11 2007/11/30 22:37:22 oliverschmidt Exp $ * $Id: ctk.c,v 1.12 2007/12/14 23:34:19 oliverschmidt Exp $
* *
*/ */
@ -60,14 +60,19 @@ static unsigned char height, width;
static unsigned char mode; static unsigned char mode;
#if CTK_CONF_WINDOWS
static struct ctk_window desktop_window; static struct ctk_window desktop_window;
static struct ctk_window *windows; static struct ctk_window *windows;
static struct ctk_window *dialog; static struct ctk_window *dialog;
#else /* CTK_CONF_WINDOWS */
static struct ctk_window *window;
#endif /* CTK_CONF_WINDOWS */
#if CTK_CONF_MENUS #if CTK_CONF_MENUS
static struct ctk_menus menus; static struct ctk_menus menus;
static struct ctk_menu *lastmenu; static struct ctk_menu *lastmenu;
static struct ctk_menu desktopmenu; static struct ctk_menu desktopmenu;
static unsigned char maxnitems;
#endif /* CTK_CONF_MENUS */ #endif /* CTK_CONF_MENUS */
#ifndef NULL #ifndef NULL
@ -85,7 +90,6 @@ static struct ctk_menu desktopmenu;
static unsigned char redraw; static unsigned char redraw;
static struct ctk_widget *redraw_widgets[MAX_REDRAWWIDGETS]; static struct ctk_widget *redraw_widgets[MAX_REDRAWWIDGETS];
static unsigned char redraw_widgetptr; static unsigned char redraw_widgetptr;
static unsigned char maxnitems;
#if CTK_CONF_ICONS #if CTK_CONF_ICONS
static unsigned char iconx, icony; static unsigned char iconx, icony;
@ -133,24 +137,27 @@ process_event_t
ctk_signal_hyperlink_activate, ctk_signal_hyperlink_activate,
/** Same as ctk_signal_widget_select. */ /** Same as ctk_signal_widget_select. */
ctk_signal_hyperlink_hover, ctk_signal_hyperlink_hover;
#if CTK_CONF_MENUS
/** Emitted when a menu item is activated. The number of the menu /** Emitted when a menu item is activated. The number of the menu
item is passed as signal data. */ item is passed as signal data. */
ctk_signal_menu_activate, process_event_t ctk_signal_menu_activate;
#endif /* CTK_CONF_MENUS */
/** Emitted when a window is closed. A pointer to the window is /** Emitted when a window is closed. A pointer to the window is
passed as signal data. */ passed as signal data. */
ctk_signal_window_close, process_event_t ctk_signal_window_close;
#if CTK_CONF_MOUSE_SUPPORT
/** Emitted when the mouse pointer is moved. A NULL pointer is /** Emitted when the mouse pointer is moved. A NULL pointer is
passed as signal data and it is up to the listening process to passed as signal data and it is up to the listening process to
check the position of the mouse using the CTK mouse API.*/ check the position of the mouse using the CTK mouse API.*/
ctk_signal_pointer_move, process_event_t ctk_signal_pointer_move,
/** Emitted when a mouse button is pressed. The button is passed as /** Emitted when a mouse button is pressed. The button is passed as
signal data to the listening process. */ signal data to the listening process. */
ctk_signal_pointer_button; ctk_signal_pointer_button;
#endif /* CTK_CONF_MOUSE_SUPPORT */
#if CTK_CONF_SCREENSAVER #if CTK_CONF_SCREENSAVER
/** Emitted when the user has been idle long enough for the /** Emitted when the user has been idle long enough for the
@ -307,6 +314,7 @@ ctk_icon_add(CC_REGISTER_ARG struct ctk_widget *icon, struct process *p)
arrange_icons(); arrange_icons();
#endif /* CTK_CONF_ICONS */ #endif /* CTK_CONF_ICONS */
} }
#if CTK_CONF_WINDOWS
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
* Open a dialog box. * Open a dialog box.
@ -332,6 +340,7 @@ ctk_dialog_close(void)
dialog = NULL; dialog = NULL;
redraw |= REDRAW_ALL; redraw |= REDRAW_ALL;
} }
#endif /* CTK_CONF_WINDOWS */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
* Open a window, or bring window to front if already open. * Open a window, or bring window to front if already open.
@ -342,6 +351,7 @@ ctk_dialog_close(void)
void void
ctk_window_open(CC_REGISTER_ARG struct ctk_window *w) ctk_window_open(CC_REGISTER_ARG struct ctk_window *w)
{ {
#if CTK_CONF_WINDOWS
struct ctk_window *w2; struct ctk_window *w2;
/* Check if already open. */ /* Check if already open. */
@ -371,6 +381,10 @@ ctk_window_open(CC_REGISTER_ARG struct ctk_window *w)
w->prev = NULL; w->prev = NULL;
} }
} }
#else /* CTK_CONF_WINDOWS */
window = w;
debug_printf("open:%d -> %d\n",w,window);
#endif /* CTK_CONF_WINDOWS */
#if CTK_CONF_MENUS #if CTK_CONF_MENUS
/* Recreate the Desktop menu's window entries.*/ /* Recreate the Desktop menu's window entries.*/
@ -433,6 +447,7 @@ ctk_window_close(struct ctk_window *w)
redraw |= REDRAW_ALL; redraw |= REDRAW_ALL;
#endif /* CTK_CONF_WINDOWCLOSE */ #endif /* CTK_CONF_WINDOWCLOSE */
} }
#if CTK_CONF_WINDOWS
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
* \internal Create the move and close buttons on the window titlebar. * \internal Create the move and close buttons on the window titlebar.
@ -466,6 +481,7 @@ make_windowbuttons(CC_REGISTER_ARG struct ctk_window *window)
#endif /* CTK_CONF_WINDOWCLOSE */ #endif /* CTK_CONF_WINDOWCLOSE */
CTK_WIDGET_ADD(window, &window->closebutton); CTK_WIDGET_ADD(window, &window->closebutton);
} }
#endif /* CTK_CONF_WINDOWS */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
* Remove all widgets from a window. * Remove all widgets from a window.
@ -478,7 +494,9 @@ ctk_window_clear(struct ctk_window *w)
{ {
w->active = w->inactive = w->focused = NULL; w->active = w->inactive = w->focused = NULL;
#if CTK_CONF_WINDOWS
make_windowbuttons(w); make_windowbuttons(w);
#endif /* CTK_CONF_WINDOWS */
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
@ -548,9 +566,11 @@ ctk_menu_remove(struct ctk_menu *menu)
static void CC_FASTCALL static void CC_FASTCALL
do_redraw_all(unsigned char clipy1, unsigned char clipy2) do_redraw_all(unsigned char clipy1, unsigned char clipy2)
{ {
struct ctk_window *w; #if CTK_CONF_WINDOWS
static struct ctk_widget *widget; static struct ctk_widget *widget;
struct ctk_window *w;
unsigned char focus; unsigned char focus;
#endif /* CTK_CONF_WINDOWS */
if(mode != CTK_MODE_NORMAL && if(mode != CTK_MODE_NORMAL &&
mode != CTK_MODE_WINDOWMOVE) { mode != CTK_MODE_WINDOWMOVE) {
@ -559,6 +579,7 @@ do_redraw_all(unsigned char clipy1, unsigned char clipy2)
ctk_draw_clear(clipy1, clipy2); ctk_draw_clear(clipy1, clipy2);
#if CTK_CONF_WINDOWS
/* Draw widgets in root window */ /* Draw widgets in root window */
for(widget = desktop_window.active; for(widget = desktop_window.active;
widget != NULL; widget = widget->next) { widget != NULL; widget = widget->next) {
@ -588,11 +609,19 @@ do_redraw_all(unsigned char clipy1, unsigned char clipy2)
if(dialog != NULL) { if(dialog != NULL) {
ctk_draw_dialog(dialog); ctk_draw_dialog(dialog);
} }
#else /* CTK_CONF_WINDOWS */
debug_printf("all: w:%d c1:%d c1:%d\n",window,clipy1,clipy2);
if(window != NULL) {
ctk_draw_clear_window(window, CTK_FOCUS_WINDOW, clipy1, clipy2);
ctk_draw_window(window, CTK_FOCUS_WINDOW, clipy1, clipy2, 0);
}
#endif /* CTK_CONF_WINDOWS */
#if CTK_CONF_MENUS #if CTK_CONF_MENUS
ctk_draw_menus(&menus); ctk_draw_menus(&menus);
#endif /* CTK_CONF_MENUS */ #endif /* CTK_CONF_MENUS */
} }
#if CTK_CONF_WINDOWS
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
* Redraw the entire desktop. * Redraw the entire desktop.
@ -620,6 +649,7 @@ ctk_desktop_redraw(struct ctk_desktop *d)
redraw |= REDRAW_ALL; redraw |= REDRAW_ALL;
} }
} }
#endif /* CTK_CONF_WINDOWS */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
* Redraw a window. * Redraw a window.
@ -639,15 +669,17 @@ ctk_window_redraw(struct ctk_window *w)
return; return;
} }
#if CTK_CONF_WINDOWS
if(w == dialog) { if(w == dialog) {
ctk_draw_dialog(w); ctk_draw_dialog(w);
} else if(dialog == NULL && } else if(dialog == NULL &&
#if CTK_CONF_MENUS #if CTK_CONF_MENUS
menus.open == NULL && menus.open == NULL &&
#endif /* CTK_CONF_MENUS */ #endif /* CTK_CONF_MENUS */
windows == w) { windows == w)
ctk_draw_window(w, CTK_FOCUS_WINDOW, #endif /* CTK_CONF_WINDOWS */
0, height, 0); {
ctk_draw_window(w, CTK_FOCUS_WINDOW, 0, height, 0);
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -665,7 +697,7 @@ window_new(CC_REGISTER_ARG struct ctk_window *window,
unsigned char w, unsigned char h, unsigned char w, unsigned char h,
char *title) char *title)
{ {
#if CTK_CONF_WINDOWS
if(w >= width - 2) { if(w >= width - 2) {
window->x = 0; window->x = 0;
} else { } else {
@ -676,6 +708,10 @@ window_new(CC_REGISTER_ARG struct ctk_window *window,
} else { } else {
window->y = (height - h - 2 - ctk_draw_windowtitle_height) / 2; window->y = (height - h - 2 - ctk_draw_windowtitle_height) / 2;
} }
#else /* CTK_CONF_WINDOWS */
window->x = -1;
window->y = -1;
#endif /* CTK_CONF_WINDOWS */
window->w = w; window->w = w;
window->h = h; window->h = h;
@ -686,7 +722,6 @@ window_new(CC_REGISTER_ARG struct ctk_window *window,
window->titlelen = 0; window->titlelen = 0;
} }
window->next = window->prev = NULL; window->next = window->prev = NULL;
/* window->owner = DISPATCHER_CURRENT();*/
window->owner = PROCESS_CURRENT(); window->owner = PROCESS_CURRENT();
window->active = window->inactive = window->focused = NULL; window->active = window->inactive = window->focused = NULL;
} }
@ -716,8 +751,11 @@ ctk_window_new(struct ctk_window *window,
{ {
window_new(window, w, h, title); window_new(window, w, h, title);
#if CTK_CONF_WINDOWS
make_windowbuttons(window); make_windowbuttons(window);
#endif /* CTK_CONF_WINDOWS */
} }
#if CTK_CONF_WINDOWS
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
* Creates a new dialog. * Creates a new dialog.
@ -737,6 +775,7 @@ ctk_dialog_new(CC_REGISTER_ARG struct ctk_window *dialog,
{ {
window_new(dialog, w, h, NULL); window_new(dialog, w, h, NULL);
} }
#endif /* CTK_CONF_WINDOWS */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
* Creates a new menu. * Creates a new menu.
@ -851,11 +890,14 @@ widget_redraw(struct ctk_widget *widget)
#endif /* CTK_CONF_MENUS */ #endif /* CTK_CONF_MENUS */
{ {
window = widget->window; window = widget->window;
#if CTK_CONF_WINDOWS
if(window == dialog) { if(window == dialog) {
ctk_draw_widget(widget, CTK_FOCUS_DIALOG, 0, height); ctk_draw_widget(widget, CTK_FOCUS_DIALOG, 0, height);
} else if(dialog == NULL && } else if(dialog == NULL &&
(window == windows || (window == windows ||
window == &desktop_window)) { window == &desktop_window))
#endif /* CTK_CONF_WINDOWS */
{
ctk_draw_widget(widget, CTK_FOCUS_WINDOW, 0, height); ctk_draw_widget(widget, CTK_FOCUS_WINDOW, 0, height);
} }
} }
@ -977,9 +1019,7 @@ select_widget(struct ctk_widget *focus)
add_redrawwidget(window->focused); add_redrawwidget(window->focused);
process_post(focus->window->owner, ctk_signal_widget_select, focus); process_post(focus->window->owner, ctk_signal_widget_select, focus);
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define UP 0 #define UP 0
@ -989,11 +1029,13 @@ select_widget(struct ctk_widget *focus)
static void CC_FASTCALL static void CC_FASTCALL
switch_focus_widget(unsigned char direction) switch_focus_widget(unsigned char direction)
{ {
#if CTK_CONF_WINDOWS
register struct ctk_window *window; register struct ctk_window *window;
#endif /* CTK_CONF_WINDOWS */
register struct ctk_widget *focus; register struct ctk_widget *focus;
struct ctk_widget *widget; struct ctk_widget *widget;
#if CTK_CONF_WINDOWS
if(dialog != NULL) { if(dialog != NULL) {
window = dialog; window = dialog;
} else { } else {
@ -1005,6 +1047,11 @@ switch_focus_widget(unsigned char direction)
if(window == NULL) { if(window == NULL) {
window = &desktop_window; window = &desktop_window;
} }
#else /* CTK_CONF_WINDOWS */
if(window == NULL) {
return;
}
#endif /* CTK_CONF_WINDOWS */
focus = window->focused; focus = window->focused;
if(focus == NULL) { if(focus == NULL) {
@ -1107,7 +1154,6 @@ switch_menu_item(unsigned char updown)
} }
} }
} }
} }
#endif /* CTK_CONF_MENUS */ #endif /* CTK_CONF_MENUS */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -1115,18 +1161,20 @@ static unsigned char CC_FASTCALL
activate(CC_REGISTER_ARG struct ctk_widget *w) activate(CC_REGISTER_ARG struct ctk_widget *w)
{ {
if(w->type == CTK_WIDGET_BUTTON) { if(w->type == CTK_WIDGET_BUTTON) {
if(w == (struct ctk_widget *)&windows->closebutton) {
#if CTK_CONF_WINDOWCLOSE #if CTK_CONF_WINDOWCLOSE
if(w == (struct ctk_widget *)&windows->closebutton) {
process_post(w->window->owner, ctk_signal_window_close, windows); process_post(w->window->owner, ctk_signal_window_close, windows);
ctk_window_close(windows); ctk_window_close(windows);
return REDRAW_ALL; return REDRAW_ALL;
} else
#endif /* CTK_CONF_WINDOWCLOSE */ #endif /* CTK_CONF_WINDOWCLOSE */
} else if(w == (struct ctk_widget *)&windows->titlebutton) {
#if CTK_CONF_WINDOWMOVE #if CTK_CONF_WINDOWMOVE
if(w == (struct ctk_widget *)&windows->titlebutton) {
mode = CTK_MODE_WINDOWMOVE; mode = CTK_MODE_WINDOWMOVE;
return REDRAW_ALL; return REDRAW_ALL;
} else
#endif /* CTK_CONF_WINDOWMOVE */ #endif /* CTK_CONF_WINDOWMOVE */
} else { {
process_post(w->window->owner, ctk_signal_widget_activate, w); process_post(w->window->owner, ctk_signal_widget_activate, w);
} }
#if CTK_CONF_ICONS #if CTK_CONF_ICONS
@ -1343,7 +1391,9 @@ PROCESS_THREAD(ctk_process, ev, data)
{ {
static ctk_arch_key_t c; static ctk_arch_key_t c;
static unsigned char i; static unsigned char i;
#if CTK_CONF_WINDOWS
register struct ctk_window *window; register struct ctk_window *window;
#endif /* CTK_CONF_WINDOWS */
register struct ctk_widget *widget; register struct ctk_widget *widget;
register struct ctk_widget **widgetptr; register struct ctk_widget **widgetptr;
#if CTK_CONF_MOUSE_SUPPORT #if CTK_CONF_MOUSE_SUPPORT
@ -1355,9 +1405,6 @@ PROCESS_THREAD(ctk_process, ev, data)
PROCESS_BEGIN(); PROCESS_BEGIN();
windows = NULL;
dialog = NULL;
#if CTK_CONF_MENUS #if CTK_CONF_MENUS
ctk_menu_new(&desktopmenu, "Desktop"); ctk_menu_new(&desktopmenu, "Desktop");
make_desktopmenu(); make_desktopmenu();
@ -1371,7 +1418,9 @@ PROCESS_THREAD(ctk_process, ev, data)
ctk_restore(); ctk_restore();
#if CTK_CONF_WINDOWS
desktop_window.owner = &ctk_process; desktop_window.owner = &ctk_process;
#endif /* CTK_CONF_WINDOWS */
ctk_signal_keypress = process_alloc_event(); ctk_signal_keypress = process_alloc_event();
@ -1384,11 +1433,16 @@ PROCESS_THREAD(ctk_process, ev, data)
ctk_signal_hyperlink_activate = process_alloc_event(); ctk_signal_hyperlink_activate = process_alloc_event();
#if CTK_CONF_MENUS
ctk_signal_menu_activate = process_alloc_event(); ctk_signal_menu_activate = process_alloc_event();
#endif /* CTK_CONF_MENUS */
ctk_signal_window_close = process_alloc_event(); ctk_signal_window_close = process_alloc_event();
#if CTK_CONF_MOUSE_SUPPORT
ctk_signal_pointer_move = process_alloc_event(); ctk_signal_pointer_move = process_alloc_event();
ctk_signal_pointer_button = process_alloc_event(); ctk_signal_pointer_button = process_alloc_event();
#endif /* CTK_CONF_MOUSE_SUPPORT */
#if CTK_CONF_SCREENSAVER #if CTK_CONF_SCREENSAVER
ctk_signal_screensaver_start = process_alloc_event(); ctk_signal_screensaver_start = process_alloc_event();
@ -1674,6 +1728,7 @@ PROCESS_THREAD(ctk_process, ev, data)
c = ctk_arch_getkey(); c = ctk_arch_getkey();
#if CTK_CONF_WINDOWS
if(dialog != NULL) { if(dialog != NULL) {
window = dialog; window = dialog;
} else if(windows != NULL) { } else if(windows != NULL) {
@ -1681,6 +1736,11 @@ PROCESS_THREAD(ctk_process, ev, data)
} else { } else {
window = &desktop_window; window = &desktop_window;
} }
#else /* CTK_CONF_WINDOWS */
if(window == NULL) {
continue;
}
#endif /* CTK_CONF_WINDOWS */
widget = window->focused; widget = window->focused;
@ -1714,6 +1774,7 @@ PROCESS_THREAD(ctk_process, ev, data)
} }
break; break;
#endif /* CTK_CONF_MENUS */ #endif /* CTK_CONF_MENUS */
#if CTK_CONF_WINDOWS
case CTK_CONF_WINDOWSWITCH_KEY: case CTK_CONF_WINDOWSWITCH_KEY:
if(windows != NULL) { if(windows != NULL) {
for(window = windows; window->next != NULL; for(window = windows; window->next != NULL;
@ -1721,6 +1782,7 @@ PROCESS_THREAD(ctk_process, ev, data)
ctk_window_open(window); ctk_window_open(window);
} }
break; break;
#endif /* CTK_CONF_WINDOWS */
default: default:
if(c == CH_ENTER && if(c == CH_ENTER &&
@ -1844,6 +1906,7 @@ PROCESS_THREAD(ctk_process, ev, data)
#endif /* CTK_CONF_WINDOWMOVE */ #endif /* CTK_CONF_WINDOWMOVE */
} }
debug_printf("redraw:%d %d\n",redraw,window);
if(redraw & REDRAW_ALL) { if(redraw & REDRAW_ALL) {
do_redraw_all(1, height); do_redraw_all(1, height);
#if CTK_CONF_MENUS #if CTK_CONF_MENUS
@ -1853,6 +1916,7 @@ PROCESS_THREAD(ctk_process, ev, data)
ctk_draw_menus(&menus); ctk_draw_menus(&menus);
#endif /* CTK_CONF_MENUS */ #endif /* CTK_CONF_MENUS */
} else if(redraw & REDRAW_FOCUS) { } else if(redraw & REDRAW_FOCUS) {
#if CTK_CONF_WINDOWS
if(dialog != NULL) { if(dialog != NULL) {
ctk_window_redraw(dialog); ctk_window_redraw(dialog);
} else if(windows != NULL) { } else if(windows != NULL) {
@ -1860,6 +1924,11 @@ PROCESS_THREAD(ctk_process, ev, data)
} else { } else {
ctk_window_redraw(&desktop_window); ctk_window_redraw(&desktop_window);
} }
#else /* CTK_CONF_WINDOWS */
if(window != NULL) {
ctk_window_redraw(window);
}
#endif /* CTK_CONF_WINDOWS */
} else if(redraw & REDRAW_WIDGETS) { } else if(redraw & REDRAW_WIDGETS) {
widgetptr = redraw_widgets; widgetptr = redraw_widgets;
for(i = 0; i < MAX_REDRAWWIDGETS; ++i) { for(i = 0; i < MAX_REDRAWWIDGETS; ++i) {

View File

@ -43,7 +43,7 @@
* *
* This file is part of the Contiki desktop OS. * This file is part of the Contiki desktop OS.
* *
* $Id: ctk.h,v 1.3 2007/08/30 14:39:17 matsutsuka Exp $ * $Id: ctk.h,v 1.4 2007/12/14 23:34:19 oliverschmidt Exp $
* *
*/ */
@ -523,10 +523,17 @@ struct ctk_window {
struct ctk_label titlebutton; struct ctk_label titlebutton;
#endif /* CTK_CONF_WINDOWMOVE */ #endif /* CTK_CONF_WINDOWMOVE */
#if CTK_CONF_WINDOWS
unsigned char x, /**< The x coordinate of the window, in unsigned char x, /**< The x coordinate of the window, in
characters. */ characters. */
y; /**< The y coordinate of the window, in y; /**< The y coordinate of the window, in
characters. */ characters. */
#else /* CTK_CONF_WINDOWS */
signed char x, /**< The x coordinate of the window, in
characters. */
y; /**< The y coordinate of the window, in
characters. */
#endif /* CTK_CONF_WINDOWS */
unsigned char w, /**< The width of the window, excluding unsigned char w, /**< The width of the window, excluding
window borders. */ window borders. */
h; /**< The height of the window, h; /**< The height of the window,