source: trunk/tools/neercs/old/screen_list.c @ 2183

Last change on this file since 2183 was 2183, checked in by sam, 7 years ago

build: fix the WTFPL site URL in all code comments.

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