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

Last change on this file since 4026 was 4026, checked in by Jean-Yves Lamoureux, 11 years ago
  • Added src/python.c and ctrl-a-e to open (non-existing yet) single-command executer. Do not document this yet (hint hint)
File size: 5.8 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->python_command = 0;
61    screen_list->status = 1;
62    screen_list->eyecandy = 1;
63    screen_list->border_size = 1;
64    screen_list->title = NULL;
65    screen_list->window_list = 0;
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->in_screensaver = 0;
77    screen_list->locked = 0;
78    screen_list->lock_offset = 0;
79    screen_list->lock_on_detach = 0;
80    screen_list->attached = 1;
81    screen_list->socket[SOCK_SERVER] = 0;
82    screen_list->socket[SOCK_CLIENT] = 0;
83    screen_list->socket_dir = NULL;
84    screen_list->socket_path[SOCK_SERVER] = NULL;
85    screen_list->socket_path[SOCK_CLIENT] = NULL;
86    screen_list->session_name = NULL;
87    screen_list->default_shell = NULL;
88    screen_list->user_path = NULL;
89    screen_list->autolock_timeout = -1;
90    screen_list->to_grab = NULL;
91    screen_list->to_start = NULL;
92    screen_list->nb_to_grab = 0;
93    screen_list->attach = 0;
94    screen_list->forceattach = 0;
95   
96    screen_list->force_refresh = 0;
97    screen_list->cube.in_switch = 0;
98    screen_list->cube.duration = 1000000;
99   
100   
101    screen_list->recurrent_list = NULL;
102    screen_list->cv = NULL;
103    screen_list->dp = NULL;
104   
105    memset(screen_list->lockmsg, 0, 1024);
106    memset(screen_list->lockpass, 0, 1024);
107   
108   
109    /* Build local config file path */
110    user_dir = getenv("HOME");
111    if (!user_dir)
112    {
113        user_info = getpwuid(getuid());
114        if (user_info)
115        {
116            user_dir = user_info->pw_dir;
117        }
118    }
119    if (user_dir)
120    {
121        screen_list->user_path =
122        malloc(strlen(user_dir) + strlen("/.neercsrc") + 1);
123        sprintf(screen_list->user_path, "%s/%s", user_dir, ".neercsrc");
124    }
125   
126   
127    screen_list->recurrent_list =
128    (struct recurrent_list *)malloc(sizeof(struct recurrent_list));
129    screen_list->recurrent_list->recurrent =
130    (struct recurrent **)malloc(sizeof(struct recurrent *));
131    if (!screen_list->recurrent_list->recurrent)
132    {
133        fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__,
134                __LINE__);
135        free(screen_list);
136        free(screen_list->screen);
137        return NULL;
138    }
139    screen_list->recurrent_list->count = 0;
140   
141    return screen_list;
142}
143
144void free_screen_list(struct screen_list *screen_list)
145{
146    int i;
147    struct option *option;
148   
149    if (screen_list->dp)
150        caca_free_display(screen_list->dp);
151   
152    if (screen_list->cv)
153        caca_free_canvas(screen_list->cv);
154   
155    for (i = 0; i < screen_list->count; i++)
156    {
157        destroy_screen(screen_list->screen[i]);
158    }
159   
160    if (screen_list->socket_path[SOCK_SERVER])
161        free(screen_list->socket_path[SOCK_SERVER]);
162   
163    if (screen_list->socket_path[SOCK_CLIENT])
164    {
165        unlink(screen_list->socket_path[SOCK_CLIENT]);
166        free(screen_list->socket_path[SOCK_CLIENT]);
167    }
168   
169    if (screen_list->socket[SOCK_CLIENT])
170        close(screen_list->socket[SOCK_CLIENT]);
171   
172    if (screen_list->socket[SOCK_SERVER])
173        close(screen_list->socket[SOCK_SERVER]);
174   
175    if (screen_list->screen)
176        free(screen_list->screen);
177   
178    option = screen_list->config;
179   
180    while (option)
181    {
182        struct option *kromeugnon = option;
183        option = option->next;
184        if (kromeugnon->key)
185            free(kromeugnon->key);
186        if (kromeugnon->value)
187            free(kromeugnon->value);
188        free(kromeugnon);
189    }
190   
191    for (i = 0; i < screen_list->recurrent_list->count; i++)
192    {
193        remove_recurrent(screen_list->recurrent_list, i);
194        i = 0;
195    }
196   
197    if (screen_list->recurrent_list->recurrent)
198        free(screen_list->recurrent_list->recurrent);
199    if (screen_list->recurrent_list)
200        free(screen_list->recurrent_list);
201   
202    if (screen_list->session_name)
203        free(screen_list->session_name);
204   
205    if (screen_list->title)
206        free(screen_list->title);
207   
208    free(screen_list);
209}
Note: See TracBrowser for help on using the repository browser.