This one refactors the previous patch to use event loop when shifting
monitors. I have tested it now and it seems to be working alright, I
guess I have done something wrong the first time I tried this.
---
 monitor.c | 32 ++++++++++++++++++++++++++++++--
 tmux.h    |  1 +
 2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/monitor.c b/monitor.c
index d0f3a13..fd4c9a2 100644
--- a/monitor.c
+++ b/monitor.c
@@ -166,11 +166,41 @@ monitor_enter(struct monitors *head, struct monitor_node *m, struct cmd_q *cmdq,
 	return 0;
 }
 
+struct shift_evdata {
+	struct monitors *head;
+	char *name;
+};
+
 void
 monitor_shift(struct monitors *head, struct monitor_node *m)
 {
+	struct shift_evdata *evdata;
+	struct event ev;
+	struct timeval tv = {0, 0};
+
+	evdata = xmalloc(sizeof *evdata);
+	evdata->head = head;
+	evdata->name = xstrdup(m->name);
+	evtimer_set(&ev, monitor_shift_handler, evdata);
+	evtimer_add(&ev, &tv);
+}
+
+void monitor_shift_handler(int fd, short ev, void *data)
+{
+	struct shift_evdata *evdata = (struct shift_evdata *)data;
+	struct monitors *head = evdata->head;
+	struct monitor_node *m = monitor_find(head, evdata->name);
 	struct cmdq_node *q;
 
+	(void)fd;
+	(void)ev;
+
+	free(evdata->name);
+	free(evdata);
+
+	if (m == NULL)
+		return;
+
 	/* Release the lock. */
 	m->pane = NULL;
 
@@ -202,5 +232,3 @@ monitor_shift(struct monitors *head, struct monitor_node *m)
 		free(m);
 	}
 }
-
-
diff --git a/tmux.h b/tmux.h
index 94b3719..e7495aa 100644
--- a/tmux.h
+++ b/tmux.h
@@ -2416,5 +2416,6 @@ void monitor_signal_move_cmdq(struct monitors *, struct monitor_node *);
 int monitor_enter(struct monitors *, struct monitor_node *, struct cmd_q *cmdq,
                   enum monitor_options);
 void monitor_shift(struct monitors *, struct monitor_node *);
+void monitor_shift_handler(int, short, void *);
 
 #endif /* TMUX_H */
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to