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

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