diff options
author | Steven Rostedt <srostedt@redhat.com> | 2011-02-21 18:20:14 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-02-21 20:42:09 -0500 |
commit | ced46417ac738077b949aca89edc7b9cbe59442e (patch) | |
tree | da2b6a17a452998d75ee459f060bcba4cbe16d99 | |
parent | cfe5212d7a016c9143cd891bd1ab3bedd9bf5c44 (diff) |
kernelshark: Push and pop cursor
Use a stack to save off the parent window cursor and restoring it
via the stack. This way multiple trace_set_cursor() will work with
multiple trace_put_cursor(). We can save and restore the cursor
of the main window at various levels.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-dialog.c | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/trace-dialog.c b/trace-dialog.c index d5d8c04..1cbbb44 100644 --- a/trace-dialog.c +++ b/trace-dialog.c | |||
@@ -38,7 +38,6 @@ static GtkWidget *statuspix; | |||
38 | static GString *statusstr; | 38 | static GString *statusstr; |
39 | 39 | ||
40 | static GtkWidget *parent_window; | 40 | static GtkWidget *parent_window; |
41 | static GdkCursor *parent_cursor; | ||
42 | 41 | ||
43 | static void (*alt_warning)(const char *fmt, va_list ap); | 42 | static void (*alt_warning)(const char *fmt, va_list ap); |
44 | 43 | ||
@@ -89,6 +88,36 @@ void trace_dialog_register_window(GtkWidget *window) | |||
89 | parent_window = window; | 88 | parent_window = window; |
90 | } | 89 | } |
91 | 90 | ||
91 | static struct cursor_stack { | ||
92 | struct cursor_stack *next; | ||
93 | GdkCursor *cursor; | ||
94 | } *cursor_stack; | ||
95 | |||
96 | static void push_cursor(GdkCursor *cursor) | ||
97 | { | ||
98 | struct cursor_stack *item; | ||
99 | |||
100 | item = malloc_or_die(sizeof(item)); | ||
101 | item->next = cursor_stack; | ||
102 | cursor_stack = item; | ||
103 | item->cursor = cursor; | ||
104 | } | ||
105 | |||
106 | static GdkCursor *pop_cursor(void) | ||
107 | { | ||
108 | struct cursor_stack *item; | ||
109 | GdkCursor *cursor; | ||
110 | |||
111 | item = cursor_stack; | ||
112 | if (!item) | ||
113 | return NULL; | ||
114 | |||
115 | cursor_stack = item->next; | ||
116 | cursor = item->cursor; | ||
117 | free(item); | ||
118 | return cursor; | ||
119 | } | ||
120 | |||
92 | void trace_set_cursor(GdkCursorType type) | 121 | void trace_set_cursor(GdkCursorType type) |
93 | { | 122 | { |
94 | GdkWindow *window; | 123 | GdkWindow *window; |
@@ -99,15 +128,10 @@ void trace_set_cursor(GdkCursorType type) | |||
99 | 128 | ||
100 | window = GTK_WIDGET(parent_window)->window; | 129 | window = GTK_WIDGET(parent_window)->window; |
101 | 130 | ||
102 | if (!parent_cursor) | 131 | /* save the previous cursor */ |
103 | parent_cursor = gdk_window_get_cursor(window); | 132 | cursor = gdk_window_get_cursor(window); |
104 | else { | 133 | push_cursor(cursor); |
105 | /* destroy the old one */ | 134 | |
106 | cursor = gdk_window_get_cursor(window); | ||
107 | if (cursor && cursor != parent_cursor) | ||
108 | gdk_cursor_unref(cursor); | ||
109 | } | ||
110 | |||
111 | cursor = gdk_cursor_new(type); | 135 | cursor = gdk_cursor_new(type); |
112 | if (!cursor) | 136 | if (!cursor) |
113 | die("Can't create cursor"); | 137 | die("Can't create cursor"); |
@@ -124,9 +148,11 @@ void trace_put_cursor(void) | |||
124 | 148 | ||
125 | window = GTK_WIDGET(parent_window)->window; | 149 | window = GTK_WIDGET(parent_window)->window; |
126 | cursor = gdk_window_get_cursor(window); | 150 | cursor = gdk_window_get_cursor(window); |
127 | if (cursor && cursor != parent_cursor) | 151 | if (cursor) |
128 | gdk_cursor_unref(cursor); | 152 | gdk_cursor_unref(cursor); |
129 | gdk_window_set_cursor(window, parent_cursor); | 153 | |
154 | cursor = pop_cursor(); | ||
155 | gdk_window_set_cursor(window, cursor); | ||
130 | } | 156 | } |
131 | 157 | ||
132 | void trace_freeze_all(void) | 158 | void trace_freeze_all(void) |