]>
Dogcows Code - chaz/openbox/blob - plugins/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 frame_frame_gravity(c
->frame
, &x
, &y
); /* get where the client
61 client_configure(c
, Corner_TopLeft
, x
, y
,
62 c
->area
.width
, c
->area
.height
,
71 static void strip_tabs(char *s
)
80 static void set_history(Client
*c
)
82 struct HistoryItem
*hi
;
87 hi
= g_new(struct HistoryItem
, 1);
88 history
= g_slist_append(history
, hi
);
89 hi
->name
= g_strdup(c
->name
);
91 hi
->class = g_strdup(c
->class);
92 strip_tabs(hi
->class);
93 hi
->role
= g_strdup(c
->role
);
97 hi
->x
= c
->frame
->area
.x
;
98 hi
->y
= c
->frame
->area
.y
;
102 static void event(ObEvent
*e
, void *foo
)
104 g_assert(e
->type
== Event_Client_Destroy
);
106 set_history(e
->data
.c
.client
);
109 static void save_history()
115 struct HistoryItem
*hi
;
118 io
= g_io_channel_new_file(history_path
, "w", &err
);
120 for (it
= history
; it
!= NULL
; it
= it
->next
) {
122 buf
= g_string_sized_new(0);
123 buf
=g_string_append(buf
, hi
->name
);
124 g_string_append_c(buf
, '\t');
125 buf
=g_string_append(buf
, hi
->class);
126 g_string_append_c(buf
, '\t');
127 buf
=g_string_append(buf
, hi
->role
);
128 g_string_append_c(buf
, '\t');
129 g_string_append_printf(buf
, "%d", hi
->x
);
130 buf
=g_string_append_c(buf
, '\t');
131 g_string_append_printf(buf
, "%d", hi
->y
);
132 buf
=g_string_append_c(buf
, '\n');
133 if (g_io_channel_write_chars(io
, buf
->str
, buf
->len
, &ret
, &err
) !=
136 g_string_free(buf
, TRUE
);
138 g_io_channel_unref(io
);
142 static void load_history()
148 struct HistoryItem
*hi
= NULL
;
150 io
= g_io_channel_new_file(history_path
, "r", &err
);
152 while (g_io_channel_read_line(io
, &buf
, NULL
, NULL
, &err
) ==
153 G_IO_STATUS_NORMAL
) {
154 hi
= g_new0(struct HistoryItem
, 1);
157 if ((c
= strchr(b
, '\t')) == NULL
) break;
159 hi
->name
= g_strdup(b
);
162 if ((c
= strchr(b
, '\t')) == NULL
) break;
164 hi
->class = g_strdup(b
);
167 if ((c
= strchr(b
, '\t')) == NULL
) break;
169 hi
->role
= g_strdup(b
);
172 if ((c
= strchr(b
, '\t')) == NULL
) break;
177 if ((c
= strchr(b
, '\n')) == NULL
) break;
186 history
= g_slist_append(history
, hi
);
189 g_io_channel_unref(io
);
202 void history_startup()
208 path
= g_build_filename(g_get_home_dir(), ".openbox", "history", NULL
);
209 history_path
= g_strdup_printf("%s.%d", path
, ob_screen
);
212 load_history(); /* load from the historydb file */
214 dispatch_register(Event_Client_Destroy
, (EventHandler
)event
, NULL
);
217 void history_shutdown()
221 save_history(); /* save to the historydb file */
222 for (it
= history
; it
!= NULL
; it
= it
->next
)
224 g_slist_free(history
);
226 dispatch_register(0, (EventHandler
)event
, NULL
);
228 g_free(history_path
);
This page took 0.041324 seconds and 4 git commands to generate.