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

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