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

Last change on this file since 4060 was 4060, checked in by Jean-Yves Lamoureux, 11 years ago
  • Moved lock-related stuff to struct lock
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->mini = 1;
59    screen_list->help = 0;
60    screen_list->status = 1;
61    screen_list->eyecandy = 1;
62    screen_list->border_size = 1;
63    screen_list->title = NULL;
64    screen_list->window_list = 0;
65    screen_list->wm_type = WM_VSPLIT;
66    screen_list->in_bell = 0;
67    screen_list->changed = 0;
68    screen_list->requested_delay = 0;
69    screen_list->delay = 1000 / 60;     /* Don't refresh more than 60 times
70                                         per second */
71    screen_list->pty = screen_list->prevpty = 0;
72    screen_list->dont_update_coords = 0;
73    screen_list->screensaver.timeout = (60*5) * 1000000;
74    screen_list->screensaver.data = NULL;
75    screen_list->screensaver.in_screensaver = 0;
76    screen_list->lock.autolock_timeout = -1;
77    screen_list->lock.locked = 0;
78    screen_list->lock.lock_offset = 0;
79    screen_list->lock.lock_on_detach = 0;
80    screen_list->comm.attached = 1;
81    screen_list->comm.socket[SOCK_SERVER] = 0;
82    screen_list->comm.socket[SOCK_CLIENT] = 0;
83    screen_list->comm.socket_dir = NULL;
84    screen_list->comm.socket_path[SOCK_SERVER] = NULL;
85    screen_list->comm.socket_path[SOCK_CLIENT] = NULL;
86    screen_list->comm.session_name = NULL;
87    screen_list->default_shell = NULL;
88    screen_list->user_path = NULL;
89    screen_list->to_grab = NULL;
90    screen_list->to_start = NULL;
91    screen_list->nb_to_grab = 0;
92    screen_list->attach = 0;
93    screen_list->forceattach = 0;
94    screen_list->need_refresh = 0;
95
96    screen_list->force_refresh = 0;
97    screen_list->cube.in_switch = 0;
98    screen_list->cube.duration = 1000000;
99   
100    screen_list->python_command = 0;
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);
108c    memset(screen_list->lock.lockpass, 0, 1024);
109   
110   
111    /* Build local config file path */
112    user_dir = getenv("HOME");
113    if (!user_dir)
114    {
115        user_info = getpwuid(getuid());
116        if (user_info)
117        {
118            user_dir = user_info->pw_dir;
119        }
120    }
121    if (user_dir)
122    {
123        screen_list->user_path =
124        malloc(strlen(user_dir) + strlen("/.neercsrc") + 1);
125        sprintf(screen_list->user_path, "%s/%s", user_dir, ".neercsrc");
126    }
127   
128   
129    screen_list->recurrent_list =
130    (struct recurrent_list *)malloc(sizeof(struct recurrent_list));
131    screen_list->recurrent_list->recurrent =
132    (struct recurrent **)malloc(sizeof(struct recurrent *));
133    if (!screen_list->recurrent_list->recurrent)
134    {
135        fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__,
136                __LINE__);
137        free(screen_list);
138        free(screen_list->screen);
139        return NULL;
140    }
141    screen_list->recurrent_list->count = 0;
142   
143    return screen_list;
144}
145
146void free_screen_list(struct screen_list *screen_list)
147{
148    int i;
149    struct option *option;
150   
151    if (screen_list->dp)
152        caca_free_display(screen_list->dp);
153   
154    if (screen_list->cv)
155        caca_free_canvas(screen_list->cv);
156   
157    for (i = 0; i < screen_list->count; i++)
158    {
159        destroy_screen(screen_list->screen[i]);
160    }
161   
162    if (screen_list->comm.socket_path[SOCK_SERVER])
163    {
164        /* FIXME test that we are the server */
165        if (!screen_list->dp)
166            unlink(screen_list->comm.socket_path[SOCK_SERVER]);
167        free(screen_list->comm.socket_path[SOCK_SERVER]);
168    }
169   
170    if (screen_list->comm.socket_path[SOCK_CLIENT])
171    {
172        /* FIXME test that we are the client */
173        if (screen_list->dp)
174
175            unlink(screen_list->comm.socket_path[SOCK_CLIENT]);
176        free(screen_list->comm.socket_path[SOCK_CLIENT]);
177    }
178   
179    if (screen_list->comm.socket[SOCK_CLIENT])
180        close(screen_list->comm.socket[SOCK_CLIENT]);
181   
182    if (screen_list->comm.socket[SOCK_SERVER])
183        close(screen_list->comm.socket[SOCK_SERVER]);
184   
185    if (screen_list->screen)
186        free(screen_list->screen);
187   
188    option = screen_list->config;
189   
190    while (option)
191    {
192        struct option *kromeugnon = option;
193        option = option->next;
194        if (kromeugnon->key)
195            free(kromeugnon->key);
196        if (kromeugnon->value)
197            free(kromeugnon->value);
198        free(kromeugnon);
199    }
200   
201    for (i = 0; i < screen_list->recurrent_list->count; i++)
202    {
203        remove_recurrent(screen_list->recurrent_list, i);
204        i = 0;
205    }
206   
207    if (screen_list->recurrent_list->recurrent)
208        free(screen_list->recurrent_list->recurrent);
209    if (screen_list->recurrent_list)
210        free(screen_list->recurrent_list);
211   
212    if (screen_list->comm.session_name)
213        free(screen_list->comm.session_name);
214   
215    if (screen_list->title)
216        free(screen_list->title);
217   
218    free(screen_list);
219}
Note: See TracBrowser for help on using the repository browser.