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

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