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

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