]>
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"
5 #include "kernel/screen.h"
21 static GSList
*history
= NULL
;
22 static char *history_path
= NULL
;
24 static struct HistoryItem
*find_history(Client
*c
)
27 struct HistoryItem
*hi
= NULL
;
30 for (it
= history
; it
!= NULL
; it
= it
->next
) {
32 g_assert(hi
->name
!= NULL
);
33 g_assert(hi
->class != NULL
);
34 g_assert(hi
->role
!= NULL
);
35 g_assert(c
->name
!= NULL
);
36 g_assert(c
->class != NULL
);
37 g_assert(c
->role
!= NULL
);
38 if (!strcmp(hi
->name
, c
->name
) &&
39 !strcmp(hi
->class, c
->class) &&
40 !strcmp(hi
->role
, c
->role
))
46 gboolean
place_history(Client
*c
)
48 struct HistoryItem
*hi
;
53 if (hi
!= NULL
&& !hi
->placed
) {
55 if (ob_state
!= State_Starting
) {
59 /* make sure the window is on the display */
60 if (x
>= screen_physical_size
.width
||
61 y
>= screen_physical_size
.height
||
62 x
+ c
->frame
->area
.width
< 1 ||
63 y
+ c
->frame
->area
.height
< 1)
66 frame_frame_gravity(c
->frame
, &x
, &y
); /* get where the client
68 client_configure(c
, Corner_TopLeft
, x
, y
,
69 c
->area
.width
, c
->area
.height
,
78 static void strip_tabs(char *s
)
87 static void set_history(Client
*c
)
89 struct HistoryItem
*hi
;
94 hi
= g_new(struct HistoryItem
, 1);
95 history
= g_slist_append(history
, hi
);
96 hi
->name
= g_strdup(c
->name
);
98 hi
->class = g_strdup(c
->class);
99 strip_tabs(hi
->class);
100 hi
->role
= g_strdup(c
->role
);
101 strip_tabs(hi
->role
);
104 hi
->x
= c
->frame
->area
.x
;
105 hi
->y
= c
->frame
->area
.y
;
109 static void event(ObEvent
*e
, void *foo
)
111 g_assert(e
->type
== Event_Client_Destroy
);
113 set_history(e
->data
.c
.client
);
116 static void save_history()
122 struct HistoryItem
*hi
;
125 io
= g_io_channel_new_file(history_path
, "w", &err
);
127 for (it
= history
; it
!= NULL
; it
= it
->next
) {
129 buf
= g_string_sized_new(0);
130 buf
=g_string_append(buf
, hi
->name
);
131 g_string_append_c(buf
, '\t');
132 buf
=g_string_append(buf
, hi
->class);
133 g_string_append_c(buf
, '\t');
134 buf
=g_string_append(buf
, hi
->role
);
135 g_string_append_c(buf
, '\t');
136 g_string_append_printf(buf
, "%d", hi
->x
);
137 buf
=g_string_append_c(buf
, '\t');
138 g_string_append_printf(buf
, "%d", hi
->y
);
139 buf
=g_string_append_c(buf
, '\n');
140 if (g_io_channel_write_chars(io
, buf
->str
, buf
->len
, &ret
, &err
) !=
143 g_string_free(buf
, TRUE
);
145 g_io_channel_unref(io
);
149 static void load_history()
155 struct HistoryItem
*hi
= NULL
;
157 io
= g_io_channel_new_file(history_path
, "r", &err
);
159 while (g_io_channel_read_line(io
, &buf
, NULL
, NULL
, &err
) ==
160 G_IO_STATUS_NORMAL
) {
161 hi
= g_new0(struct HistoryItem
, 1);
164 if ((c
= strchr(b
, '\t')) == NULL
) break;
166 hi
->name
= g_strdup(b
);
169 if ((c
= strchr(b
, '\t')) == NULL
) break;
171 hi
->class = g_strdup(b
);
174 if ((c
= strchr(b
, '\t')) == NULL
) break;
176 hi
->role
= g_strdup(b
);
179 if ((c
= strchr(b
, '\t')) == NULL
) break;
184 if ((c
= strchr(b
, '\n')) == NULL
) break;
193 history
= g_slist_append(history
, hi
);
196 g_io_channel_unref(io
);
209 void history_startup()
215 path
= g_build_filename(g_get_home_dir(), ".openbox", "history", NULL
);
216 history_path
= g_strdup_printf("%s.%d", path
, ob_screen
);
219 load_history(); /* load from the historydb file */
221 dispatch_register(Event_Client_Destroy
, (EventHandler
)event
, NULL
);
224 void history_shutdown()
228 save_history(); /* save to the historydb file */
229 for (it
= history
; it
!= NULL
; it
= it
->next
)
231 g_slist_free(history
);
233 dispatch_register(0, (EventHandler
)event
, NULL
);
235 g_free(history_path
);
This page took 0.043014 seconds and 4 git commands to generate.