OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [mw/] [src/] [demos/] [nanowm/] [wlist.c] - Blame information for rev 1765

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * NanoWM - Window Manager for Nano-X
3
 *
4
 * Copyright (C) 2000 Greg Haerr <greg@censoft.com>
5
 * Copyright (C) 2000 Alex Holden <alex@linuxhacker.org>
6
 */
7
#include <stdio.h>
8
#include <stdlib.h>
9
#define MWINCLUDECOLORS
10
#include "nano-X.h"
11
/* Uncomment this to get debugging output from this file */
12
/*#define DEBUG*/
13
 
14
#include "nanowm.h"
15
 
16
static win *windows = NULL;
17
 
18
/*
19
 * Find the windowlist entry for the specified window ID and return a pointer
20
 * to it, or NULL if it isn't in the list.
21
 */
22
win *find_window(GR_WINDOW_ID wid)
23
{
24
        win *w = windows;
25
 
26
        Dprintf("Looking for window %d... ", wid);
27
 
28
        while(w) {
29
                Dprintf("%d ", w->wid);
30
                if(w->wid == wid) {
31
                        Dprintf("found it!\n");
32
                        return w;
33
                }
34
                w = w->next;
35
        }
36
 
37
        Dprintf("Nope, %d is not in the list\n", wid);
38
        return NULL;
39
}
40
 
41
/*
42
 * Add a new entry to the front of the windowlist.
43
 * Returns -1 on failure or 0 on success.
44
 */
45
int add_window(win *window)
46
{
47
        win *w;
48
 
49
        Dprintf("Adding window %d\n", window->wid);
50
 
51
        if(!(w = malloc(sizeof(win)))) return -1;
52
 
53
        w->wid = window->wid;
54
        w->pid = window->pid;
55
        w->type = window->type;
56
        w->sizing = GR_FALSE;   /* window->sizing*/
57
        w->active = window->active;
58
        w->clientid = window->clientid;
59
        w->data = window->data;
60
        w->next = windows;
61
        windows = w;
62
 
63
        return 0;
64
}
65
 
66
/*
67
 * Remove an entry from the windowlist.
68
 * We must search through the list for it so that we can find the previous
69
 * entry in the list and fix the next pointer. The alternative is to add a
70
 * prev pointer to the structure which would increase the memory usage.
71
 * Returns -1 on failure or 0 on success.
72
 */
73
int remove_window(win *window)
74
{
75
        win *w = windows;
76
        win *prev = NULL;
77
 
78
        while(w) {
79
                if(w == window) {
80
                        if(!prev) windows = w->next;
81
                        else prev->next = w->next;
82
                        if(w->data) free(w->data);
83
                        free(w);
84
                        return 0;
85
                }
86
                prev = w;
87
                w = w->next;
88
        }
89
 
90
        return -1;
91
}
92
 
93
/*
94
 * Remove an entry and all it's children from the windowlist.
95
 * Returns -1 on failure or 0 on success.
96
 */
97
int remove_window_and_children(win *window)
98
{
99
        win *t, *w = windows;
100
        win *prev = NULL;
101
        GR_WINDOW_ID pid = window->wid;
102
 
103
        Dprintf("Removing window %d and children\n", window->wid);
104
 
105
        while(w) {
106
                Dprintf("Examining window %d (pid %d)\n", w->wid, w->pid);
107
                if((w->pid == pid) || (w == window)) {
108
                        Dprintf("Removing window %d (pid %d)\n", w->wid,
109
                                                                w->pid);
110
                        if(prev) prev->next = w->next;
111
                        else windows = w->next;
112
                        t = w->next;
113
                        if(w->data) free(w->data);
114
                        free(w);
115
                        w = t;
116
                        continue;
117
                }
118
                prev = w;
119
                w = w->next;
120
        }
121
 
122
        return -1;
123
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.