source: neercs/trunk/src/wm.c @ 2495

Last change on this file since 2495 was 2495, checked in by Jean-Yves Lamoureux, 12 years ago
  • Removed general local variables from main() and put it in struct screen_list
  • Moved most of the input handling to input.c
  • Moved lock feature to lock.c
File size: 4.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: wm.c 2360 2008-06-11 16:23:46Z 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 <stdio.h>
17#include <cucul.h>
18#include <caca.h>
19#include <stdlib.h>
20
21#include "neercs.h"
22
23
24void resize_screen(struct screen *s, int w, int h)
25{
26    cucul_canvas_t *old, *new;
27
28    if(w==s->w && h==s->h) return;
29    if(w <= 0 || h <= 0) return;
30
31    s->w = w;
32    s->h = h;
33
34    /* cucul_set_canvas_boundaries() is bugged as hell,
35     * so let's resize it by hands */
36    old = s->cv;
37    new = cucul_create_canvas(w, h);
38    cucul_blit(new, 0, 0, old, NULL);
39    s->cv = new;
40    cucul_free_canvas(old);
41    set_tty_size(s->fd, w, h);
42
43    s->orig_w = s->w;
44    s->orig_h = s->h;
45    s->orig_x = s->x;
46    s->orig_y = s->y;
47}
48
49void update_windows_props(struct screen_list *screen_list)
50{
51    if(!screen_list->count) return;
52
53    switch(screen_list->wm_type)
54    {
55    case WM_CARD:
56        update_windows_props_cards(screen_list);
57        break;
58    case WM_HSPLIT:
59        update_windows_props_hsplit(screen_list);
60        break;
61    case WM_VSPLIT:
62        update_windows_props_vsplit(screen_list);
63        break;
64    case WM_FULL:
65    default:
66        update_windows_props_full(screen_list);
67        break;
68    }
69}
70
71void update_windows_props_hsplit(struct screen_list *screen_list)
72{
73    int i;
74    int w = (screen_list->width / screen_list->count) - 1;
75    int h = (screen_list->height) - 2;
76
77    for(i = 0; i < screen_list->count; i++)
78    {
79        screen_list->screen[i]->x = (i*w)+1;
80        screen_list->screen[i]->y = 1;
81        screen_list->screen[i]->visible = 1;
82        if(i != screen_list->count -1)
83        {
84            resize_screen(screen_list->screen[i],
85                          w - 1, h);
86        } else {
87            resize_screen(screen_list->screen[i],
88                          screen_list->width - i*w - 1,
89                          h);
90        }
91    }
92}
93
94void update_windows_props_vsplit(struct screen_list *screen_list)
95{
96    int i;
97    int w = screen_list->width - 2;
98    int h = (screen_list->height / screen_list->count);
99
100    for(i = 0; i < screen_list->count; i++)
101    {
102        screen_list->screen[i]->x = 1;
103        screen_list->screen[i]->y = (i*h) + 1;
104        screen_list->screen[i]->visible = 1;
105        if(i != screen_list->count -1)
106        {
107            resize_screen(screen_list->screen[i],
108                          w, h - 2);
109        } else {
110            resize_screen(screen_list->screen[i],
111                          w,
112                          screen_list->height - i*h - 2);
113        }
114    }
115}
116
117
118void update_windows_props_full(struct screen_list *screen_list)
119{
120    int i;
121    int w = screen_list->width - 2;
122    int h = screen_list->height - 2;
123
124    for(i = 0; i < screen_list->count; i++)
125    {
126        screen_list->screen[i]->visible = 0;
127        screen_list->screen[i]->x = 1;
128        screen_list->screen[i]->y = 1;
129
130        resize_screen(screen_list->screen[i],
131                      w, h);
132    }
133    screen_list->screen[screen_list->pty]->visible = 1;
134}
135
136
137void update_windows_props_cards(struct screen_list *screen_list)
138{
139    int i;
140    int w = (screen_list->width  - screen_list->count) - 3;
141    int h = (screen_list->height - screen_list->count) - 4;
142    int x = (screen_list->width  - w) - (3*screen_list->count) + 4;
143    int y = 2 + (1*screen_list->count);
144
145    for(i = 0; i < screen_list->count; i++)
146    {
147        screen_list->screen[i]->visible = 1;
148        screen_list->screen[i]->x = x;
149        screen_list->screen[i]->y = y;
150
151        resize_screen(screen_list->screen[i],
152                      w, h);
153        x += 3;
154        y--;
155    }
156}
157
Note: See TracBrowser for help on using the repository browser.