]> git.mdlowis.com Git - archive/afm.git/commitdiff
track focused node in framelist instead of frame
authora bellenir <a@bellenir.com>
Mon, 28 Jul 2014 05:21:18 +0000 (05:21 +0000)
committera bellenir <a@bellenir.com>
Mon, 28 Jul 2014 05:21:18 +0000 (05:21 +0000)
source/main.c
source/screen.c
source/state.c
source/state.h

index 2d4dc6d2eec064424ecc167ed0b4313d9c604a3d..1d2abb24ae3c6e11ed5fe4c152274ad778593e5b 100644 (file)
@@ -3,7 +3,6 @@
 #include <stdlib.h>
 #include <signal.h>
 #include <stdlib.h>
-#include <unistd.h> /*TODO: anything using this is almost certainly broken on windows */
 #include <string.h>
 
 #include "state.h"
index 8767b4041792ca2c17a7ec0671e8ef7bb385ba71..1716a822ba4715f710f75863f7260e637836edfc 100644 (file)
@@ -20,14 +20,10 @@ static void screen_refresh_curr_frame(void);
 
 static list_t* Frame_List;
 
-static Frame_T* master_frame(void){
-    return (Frame_T*) Frame_List->head->contents;
-}
-
 void screen_init(void) {
     Frame_List = list_new();
     list_push_back(Frame_List, frame_new());
-    state_set_focused_frame(master_frame());
+    state_set_focused_node(Frame_List->head);
 }
 
 void screen_deinit(void) {
@@ -54,14 +50,27 @@ void screen_open(void) {
     state_set_screen_resized(true);
 }
 
+static int get_focused_frame_index(void){
+    int i = 0;
+    list_node_t* n = Frame_List->head;
+    while(n != state_get_focused_node() && n != Frame_List->tail){ n = n->next; i++; }
+    if(n != state_get_focused_node()) i = -1;
+    return i;
+}
+
 void screen_close(void) {
-    int num_frames = list_size(Frame_List);
-    if(num_frames > 1){
-        list_delete(Frame_List, 0);
-        state_set_focused_frame(master_frame());
+    if (Frame_List->head != Frame_List->tail) {
+        int i = get_focused_frame_index();
+        list_node_t* new_focus = state_get_focused_node()->next;
+        if(i >= 0){ /* negative if node not found */
+            list_delete(Frame_List, i);
+            // new_focus will be null if rm-d tail: set it to new tail
+            if(new_focus == NULL) new_focus = Frame_List->tail;
+            state_set_focused_node(new_focus);
+            state_set_screen_dirty(true);
+            state_set_screen_resized(true);
+        }
     }
-    state_set_screen_dirty(true);
-    state_set_screen_resized(true);
 }
 
 static void screen_place_windows(void) {
index 5972fa6a4161cb1389ea683ded455a8e6c35c530..4dbee0fab30ccc5dfe554ad2fabd5e7d848499f5 100644 (file)
@@ -1,3 +1,6 @@
+#include <stddef.h> // needed because of a bug in list.h: size_t undefined.
+#include "list.h"
+
 #include "frame.h"
 #include "state.h"
 #include "screen.h"
@@ -14,8 +17,8 @@ static bool Resized = true;
 /** Whether the aardvark should be displayed */
 static bool AardvarkOn = false;
 
-/** A pointer to the currently focused frame */
-static Frame_T* Focused_Frame = 0;
+/** A pointer to the currently focused node */
+static list_node_t* Focused_Node  = NULL;
 
 static Mode_T CurrentMode = 0;
 
@@ -51,16 +54,21 @@ void state_set_aardvark_mode(bool val) {
     AardvarkOn = val;
 }
 
+list_node_t* state_get_focused_node(void) {
+    return Focused_Node;
+}
+
 Frame_T* state_get_focused_frame(void) {
-    return Focused_Frame;
+    return Focused_Node ? (Frame_T*)Focused_Node->contents : NULL;
 }
 
 WorkDir_T* state_get_focused_workdir(void) {
-       return Focused_Frame->workdir;
+    Frame_T* focused_frame = state_get_focused_frame();
+    return focused_frame ? focused_frame->workdir : NULL;
 }
 
-void state_set_focused_frame(Frame_T *p_frame) {
-    Focused_Frame = p_frame;
+void state_set_focused_node(list_node_t *p_node) {
+    Focused_Node = p_node;
 }
 
 Mode_T state_get_mode() {
index de24383c946379415007feb8098fd66682db8e5a..d97f4a58a421a5fbbc67b293066a049de7e6a0af 100644 (file)
@@ -8,6 +8,8 @@
 #define STATE_H
 
 #include <stdbool.h>
+#include "list.h"
+
 #include "frame.h"
 #include "workdir.h"
 
@@ -22,9 +24,10 @@ bool state_get_screen_resized(void);
 void state_set_screen_resized(bool val);
 bool state_get_aardvark_mode(void);
 void state_set_aardvark_mode(bool val);
+void state_set_focused_node(list_node_t* p_node);
+list_node_t* state_get_focused_node(void);
 Frame_T* state_get_focused_frame(void);
 WorkDir_T* state_get_focused_workdir(void);
-void state_set_focused_frame(Frame_T* p_frame);
 Mode_T state_get_mode(void);
 void state_set_mode(Mode_T);