source: neercs/trunk/src/screen_list.c @ 4366

Last change on this file since 4366 was 4366, checked in by sam, 5 years ago

Clean up source code, copyright information, author names, SVN keywords...

File size: 6.2 KB
Line 
1/*
2 *  neercs        console-based window manager
3 *  Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net>
4 *                2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org>
5 *                All Rights Reserved
6 *
7 *  This program is free software. It comes without any warranty, to
8 *  the extent permitted by applicable law. You can redistribute it
9 *  and/or modify it under the terms of the Do What The Fuck You Want
10 *  To Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
13
14#include "config.h"
15
16#include <stdio.h>
17#include <string.h>
18#include <stdlib.h>
19#include <sys/types.h>
20#include <signal.h>
21#include <sys/wait.h>
22#include <errno.h>
23#include <unistd.h>
24#include <pwd.h>
25
26#include <caca.h>
27
28#include "neercs.h"
29
30struct screen_list *create_screen_list(void)
31{
32
33    struct screen_list *screen_list = NULL;
34    struct passwd *user_info;
35    char *user_dir = NULL;
36
37    /* Create screen list */
38    screen_list = (struct screen_list *)malloc(sizeof(struct screen_list));
39    if (!screen_list)
40    {
41        fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__,
42                __LINE__);
43        return NULL;
44    }
45    screen_list->screen =
46    (struct screen **)malloc(sizeof(sizeof(struct screen *)));
47    if (!screen_list->screen)
48    {
49        fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__,
50                __LINE__);
51        free(screen_list);
52        return NULL;
53    }
54
55    screen_list->count = 0;
56    screen_list->modals.mini = 1;
57    screen_list->modals.help = 0;
58    screen_list->modals.status = 1;
59    screen_list->modals.window_list = 0;
60    screen_list->modals.python_command = 0;
61    screen_list->eyecandy = 1;
62    screen_list->border_size = 1;
63    screen_list->title = NULL;
64    screen_list->wm_type = WM_VSPLIT;
65    screen_list->in_bell = 0;
66    screen_list->changed = 0;
67    screen_list->requested_delay = 0;
68    screen_list->delay = 1000 / 60;     /* Don't refresh more than 60 times
69                                         per second */
70    screen_list->pty = screen_list->prevpty = 0;
71    screen_list->dont_update_coords = 0;
72    screen_list->screensaver.timeout = (60*5) * 1000000;
73    screen_list->screensaver.data = NULL;
74    screen_list->screensaver.in_screensaver = 0;
75    screen_list->lock.autolock_timeout = -1;
76    screen_list->lock.locked = 0;
77    screen_list->lock.lock_offset = 0;
78    screen_list->lock.lock_on_detach = 0;
79    screen_list->comm.attached = 1;
80    screen_list->comm.socket[SOCK_SERVER] = 0;
81    screen_list->comm.socket[SOCK_CLIENT] = 0;
82    screen_list->comm.socket_dir = NULL;
83    screen_list->comm.socket_path[SOCK_SERVER] = NULL;
84    screen_list->comm.socket_path[SOCK_CLIENT] = NULL;
85    screen_list->comm.session_name = NULL;
86    screen_list->sys.default_shell = NULL;
87    screen_list->sys.user_path = NULL;
88    screen_list->sys.to_grab = NULL;
89    screen_list->sys.to_start = NULL;
90    screen_list->sys.nb_to_grab = 0;
91    screen_list->sys.attach = 0;
92    screen_list->sys.forceattach = 0;
93    screen_list->need_refresh = 0;
94
95    screen_list->force_refresh = 0;
96    screen_list->cube.in_switch = 0;
97    screen_list->cube.duration = 1000000;
98
99    screen_list->interpreter_props.box = NULL;
100
101    screen_list->recurrent_list = NULL;
102    screen_list->cv = NULL;
103    screen_list->dp = NULL;
104
105    memset(screen_list->lock.lockmsg, 0, 1024);
106    memset(screen_list->lock.lockpass, 0, 1024);
107
108    /* Build local config file path */
109    user_dir = getenv("HOME");
110    if (!user_dir)
111    {
112        user_info = getpwuid(getuid());
113        if (user_info)
114        {
115            user_dir = user_info->pw_dir;
116        }
117    }
118    if (user_dir)
119    {
120        screen_list->sys.user_path =
121        malloc(strlen(user_dir) + strlen("/.neercsrc") + 1);
122        sprintf(screen_list->sys.user_path, "%s/%s", user_dir, ".neercsrc");
123    }
124
125
126    screen_list->recurrent_list =
127    (struct recurrent_list *)malloc(sizeof(struct recurrent_list));
128    screen_list->recurrent_list->recurrent =
129    (struct recurrent **)malloc(sizeof(struct recurrent *));
130    if (!screen_list->recurrent_list->recurrent)
131    {
132        fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__,
133                __LINE__);
134        free(screen_list);
135        free(screen_list->screen);
136        return NULL;
137    }
138    screen_list->recurrent_list->count = 0;
139
140    return screen_list;
141}
142
143void free_screen_list(struct screen_list *screen_list)
144{
145    int i;
146    struct option *option;
147
148    if (screen_list->dp)
149        caca_free_display(screen_list->dp);
150
151    if (screen_list->cv)
152        caca_free_canvas(screen_list->cv);
153
154    for (i = 0; i < screen_list->count; i++)
155    {
156        destroy_screen(screen_list->screen[i]);
157    }
158
159    if (screen_list->comm.socket_path[SOCK_SERVER])
160    {
161        /* FIXME test that we are the server */
162        if (!screen_list->dp)
163            unlink(screen_list->comm.socket_path[SOCK_SERVER]);
164        free(screen_list->comm.socket_path[SOCK_SERVER]);
165    }
166
167    if (screen_list->comm.socket_path[SOCK_CLIENT])
168    {
169        /* FIXME test that we are the client */
170        if (screen_list->dp)
171
172            unlink(screen_list->comm.socket_path[SOCK_CLIENT]);
173        free(screen_list->comm.socket_path[SOCK_CLIENT]);
174    }
175
176    if (screen_list->comm.socket[SOCK_CLIENT])
177        close(screen_list->comm.socket[SOCK_CLIENT]);
178
179    if (screen_list->comm.socket[SOCK_SERVER])
180        close(screen_list->comm.socket[SOCK_SERVER]);
181
182    if (screen_list->screen)
183        free(screen_list->screen);
184
185    option = screen_list->config;
186
187    while (option)
188    {
189        struct option *kromeugnon = option;
190        option = option->next;
191        if (kromeugnon->key)
192            free(kromeugnon->key);
193        if (kromeugnon->value)
194            free(kromeugnon->value);
195        free(kromeugnon);
196    }
197
198    for (i = 0; i < screen_list->recurrent_list->count; i++)
199    {
200        remove_recurrent(screen_list->recurrent_list, i);
201        i = 0;
202    }
203
204    if (screen_list->recurrent_list->recurrent)
205        free(screen_list->recurrent_list->recurrent);
206    if (screen_list->recurrent_list)
207        free(screen_list->recurrent_list);
208
209    if (screen_list->comm.session_name)
210        free(screen_list->comm.session_name);
211
212    if (screen_list->title)
213        free(screen_list->title);
214
215    free(screen_list);
216}
Note: See TracBrowser for help on using the repository browser.