]>
Dogcows Code - chaz/openbox/blob - placement/history.c
1 #include "../../kernel/openbox.h"
2 #include "../../kernel/dispatch.h"
3 #include "../../kernel/frame.h"
4 #include "../../kernel/client.h"
20 static GSList
*history
= NULL
;
21 static char *history_path
= NULL
;
23 static struct HistoryItem
*find_history(Client
*c
)
26 struct HistoryItem
*hi
= NULL
;
29 for (it
= history
; it
!= NULL
; it
= it
->next
) {
31 g_assert(hi
->name
!= NULL
);
32 g_assert(hi
->class != NULL
);
33 g_assert(hi
->role
!= NULL
);
34 g_assert(c
->name
!= NULL
);
35 g_assert(c
->class != NULL
);
36 g_assert(c
->role
!= NULL
);
37 if (!strcmp(hi
->name
, c
->name
) &&
38 !strcmp(hi
->class, c
->class) &&
39 !strcmp(hi
->role
, c
->role
))
45 gboolean
place_history(Client
*c
)
47 struct HistoryItem
*hi
;
52 if (hi
!= NULL
&& !hi
->placed
) {
54 if (ob_state
!= State_Starting
) {
58 frame_frame_gravity(c
->frame
, &x
, &y
); /* get where the client
60 client_configure(c
, Corner_TopLeft
, x
, y
,
61 c
->area
.width
, c
->area
.height
,
70 static void strip_tabs(char *s
)
79 static void set_history(Client
*c
)
81 struct HistoryItem
*hi
;
86 hi
= g_new(struct HistoryItem
, 1);
87 history
= g_slist_append(history
, hi
);
88 hi
->name
= g_strdup(c
->name
);
90 hi
->class = g_strdup(c
->class);
91 strip_tabs(hi
->class);
92 hi
->role
= g_strdup(c
->role
);
96 hi
->x
= c
->frame
->area
.x
;
97 hi
->y
= c
->frame
->area
.y
;
101 static void event(ObEvent
*e
, void *foo
)
103 g_assert(e
->type
== Event_Client_Destroy
);
105 set_history(e
->data
.c
.client
);
108 static void save_history()
114 struct HistoryItem
*hi
;
117 io
= g_io_channel_new_file(history_path
, "w", &err
);
119 for (it
= history
; it
!= NULL
; it
= it
->next
) {
121 buf
= g_string_sized_new(0);
122 buf
=g_string_append(buf
, hi
->name
);
123 g_string_append_c(buf
, '\t');
124 buf
=g_string_append(buf
, hi
->class);
125 g_string_append_c(buf
, '\t');
126 buf
=g_string_append(buf
, hi
->role
);
127 g_string_append_c(buf
, '\t');
128 g_string_append_printf(buf
, "%d", hi
->x
);
129 buf
=g_string_append_c(buf
, '\t');
130 g_string_append_printf(buf
, "%d", hi
->y
);
131 buf
=g_string_append_c(buf
, '\n');
132 if (g_io_channel_write_chars(io
, buf
->str
, buf
->len
, &ret
, &err
) !=
135 g_string_free(buf
, TRUE
);
137 g_io_channel_unref(io
);
141 static void load_history()
147 struct HistoryItem
*hi
= NULL
;
149 io
= g_io_channel_new_file(history_path
, "r", &err
);
151 while (g_io_channel_read_line(io
, &buf
, NULL
, NULL
, &err
) ==
152 G_IO_STATUS_NORMAL
) {
153 hi
= g_new0(struct HistoryItem
, 1);
156 if ((c
= strchr(b
, '\t')) == NULL
) break;
158 hi
->name
= g_strdup(b
);
161 if ((c
= strchr(b
, '\t')) == NULL
) break;
163 hi
->class = g_strdup(b
);
166 if ((c
= strchr(b
, '\t')) == NULL
) break;
168 hi
->role
= g_strdup(b
);
171 if ((c
= strchr(b
, '\t')) == NULL
) break;
176 if ((c
= strchr(b
, '\n')) == NULL
) break;
185 history
= g_slist_append(history
, hi
);
188 g_io_channel_unref(io
);
201 void history_startup()
207 path
= g_build_filename(g_get_home_dir(), ".openbox", "history", NULL
);
208 history_path
= g_strdup_printf("%s.%d", path
, ob_screen
);
211 load_history(); /* load from the historydb file */
213 dispatch_register(Event_Client_Destroy
, (EventHandler
)event
, NULL
);
216 void history_shutdown()
220 save_history(); /* save to the historydb file */
221 for (it
= history
; it
!= NULL
; it
= it
->next
)
223 g_slist_free(history
);
225 dispatch_register(0, (EventHandler
)event
, NULL
);
227 g_free(history_path
);
This page took 0.041146 seconds and 4 git commands to generate.