Browse Source

Make the event handling of the console a special case.

Beoran 7 years ago
parent
commit
06e3ed9983
4 changed files with 28 additions and 12 deletions
  1. 5 2
      include/zori/zori.h
  2. 5 6
      src/react.c
  3. 16 2
      src/zori/zori.c
  4. 2 2
      src/zori/zori_screen.c

+ 5 - 2
include/zori/zori.h

@@ -325,8 +325,9 @@ struct zori_widget {
 /* An array of widget pointers. */
 struct zori_widget_array miao_of_type(struct zori_widget *);
 
-/* forward declaration. */
+/* forward declarations. */
 struct zori_screen;
+struct zori_console;
 
 /* 
  * Root level widget, my spread out over several displays. 
@@ -338,6 +339,8 @@ struct zori_root {
   struct zori_widget widget;
   /* Current active screen widget if any. */
   struct zori_screen * active_screen;
+  /* Current active console if any. */
+  struct zori_console * console;
 };
 
 /* Forward declaration of a page. */
@@ -490,7 +493,7 @@ struct zori_console *zori_console_alloc(void);
 struct zori_console *zori_console_initall(struct zori_console *self, int id, zori_rebox *bounds, struct zori_style *style);
 struct zori_console *zori_console_new(int id, zori_rebox *bounds, struct zori_style *style);
 
-
+int zori_handle_system_event(zori_system_event * sysev);
 
 #endif
 

+ 5 - 6
src/react.c

@@ -104,12 +104,11 @@ React * react_poll(React * self, void * state) {
   if(!self) return NULL;
   // yes an assignment is fine here :)
   while( (event = state_pollnew((State *)state)) ) { 
-    /* Let react react first, then if that fails, send to the console,
-    but only if it is active. If not active, send the event to ruby */
-    if(!react_react(self, event))  { 
-      if (zori_console_active(console)) { 
-        zori_console_handle(&console->widget, event);
-      } else {
+    /* Let react react first, then if that fails, send to the gui, 
+     * but only if it is active. If not active, 
+     * send the event to ruby */
+    if(!react_react(self, event))  {
+      if (zori_handle_system_event(event) != ZORI_EVENT_DONE) {
         rh_poll_event(state_ruby(state_get()), event);
       }
     }

+ 16 - 2
src/zori/zori.c

@@ -466,8 +466,18 @@ void zori_draw_all(void) {
   zori_widget_raise_overdraw_event(&the_zori_root->widget);
 }
 
-
-
+/* Dispatches system events throughout the GUI.  */
+int zori_handle_system_event(zori_system_event * sysev) {
+  /* All events are passed on to the console regardless if it is active. 
+   * Otherwise, the events go into the system. */
+  if (the_zori_root->console ) { 
+    if (zori_console_active(the_zori_root->console)) {
+      int res = zori_widget_raise_system_event(&the_zori_root->console->widget, sysev);
+      if (!zori_propagate_event_p(res)) return res;
+    }
+  }
+  return zori_widget_raise_system_event(&the_zori_root->widget, sysev);
+}
 
 
 int zori_widget_visible(struct zori_widget * widget)  {
@@ -992,6 +1002,8 @@ struct zori_console * zori_console_alloc() {
 /** Initializes a console. */
 struct zori_console * zori_console_initall(struct zori_console * self, int id, zori_rebox * bounds, struct zori_style * style) {
   if(!self) return NULL;
+  /* Allow only a single console. */
+  if (the_zori_root->console) return NULL;
   if(!zori_widget_initall(&self->widget, id, &the_zori_root->widget, bounds, style, 7, zori_console_actions)) { 
     return NULL;
   }
@@ -1011,6 +1023,8 @@ struct zori_console * zori_console_initall(struct zori_console * self, int id, z
   if (!self->input) { zori_console_done(&self->widget); return NULL; }
   self->command      = NULL;
   self->command_data = NULL;
+  /* Ony one console may be active. */
+  the_zori_root->console = self;
   return self;
 }
 

+ 2 - 2
src/zori/zori_screen.c

@@ -18,7 +18,7 @@ int zori_screen_on_mouse_axes(union zori_event * event) {
       return zori_widget_raise_system_event(&screen->active_page->widget, 
         event->sys.ev);
     }
-    return ZORI_HANDLE_DONE;
+    return ZORI_HANDLE_PASS;
 }
 
 /** Handles a system event by passing it on to the active page.  */
@@ -29,7 +29,7 @@ int zori_screen_on_sysevent(union zori_event * event) {
       return zori_widget_raise_system_event(&screen->active_page->widget, 
         event->sys.ev);
     }
-    return ZORI_HANDLE_DONE;
+    return ZORI_HANDLE_PASS;
 }