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

Last change on this file since 3503 was 3503, checked in by Pascal Terjan, 11 years ago

Avoid screens out of the canvas in card mode, and use maximum possible space

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 <caca.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    caca_canvas_t *old, *new;
27
28    if(w==s->w && h==s->h) return;
29    if(w <= 0 || h <= 0) return;
30
31    s->changed = 1;
32
33    s->w = w;
34    s->h = h;
35
36    /* caca_set_canvas_boundaries() is bugged as hell,
37     * so let's resize it by hands */
38    old = s->cv;
39    new = caca_create_canvas(w, h);
40    caca_blit(new, 0, 0, old, NULL);
41    s->cv = new;
42    caca_gotoxy(new, caca_get_cursor_x(old), caca_get_cursor_y(old));
43    caca_free_canvas(old);
44    set_tty_size(s->fd, w, h);
45
46    s->orig_w = s->w;
47    s->orig_h = s->h;
48    s->orig_x = s->x;
49    s->orig_y = s->y;
50}
51
52void update_windows_props(struct screen_list *screen_list)
53{
54    if(!screen_list->count) return;
55
56    switch(screen_list->wm_type)
57    {
58    case WM_CARD:
59        update_windows_props_cards(screen_list);
60        break;
61    case WM_HSPLIT:
62        update_windows_props_hsplit(screen_list);
63        break;
64    case WM_VSPLIT:
65        update_windows_props_vsplit(screen_list);
66        break;
67    case WM_FULL:
68    default:
69        update_windows_props_full(screen_list);
70        break;
71    }
72}
73
74void update_windows_props_hsplit(struct screen_list *screen_list)
75{
76    int i;
77    int w = (screen_list->width / screen_list->count) - 1;
78    int h = (screen_list->height) - 2;
79
80    for(i = 0; i < screen_list->count; i++)
81    {
82        screen_list->screen[i]->x = (i*w)+1;
83        screen_list->screen[i]->y = 1;
84        screen_list->screen[i]->visible = 1;
85        if(i != screen_list->count -1)
86        {
87            resize_screen(screen_list->screen[i],
88                          w - 1, h);
89        } else {
90            resize_screen(screen_list->screen[i],
91                          screen_list->width - i*w - 2,
92                          h);
93        }
94    }
95}
96
97void update_windows_props_vsplit(struct screen_list *screen_list)
98{
99    int i;
100    int w = screen_list->width - 2;
101    int h = (screen_list->height / screen_list->count);
102
103    for(i = 0; i < screen_list->count; i++)
104    {
105        screen_list->screen[i]->x = 1;
106        screen_list->screen[i]->y = (i*h) + 1;
107        screen_list->screen[i]->visible = 1;
108        if(i != screen_list->count -1)
109        {
110            resize_screen(screen_list->screen[i],
111                          w, h - 2);
112        } else {
113            resize_screen(screen_list->screen[i],
114                          w,
115                          screen_list->height - i*h - 2);
116        }
117    }
118}
119
120
121void update_windows_props_full(struct screen_list *screen_list)
122{
123    int i;
124    int w = screen_list->width - 2;
125    int h = screen_list->height - 2;
126
127    for(i = 0; i < screen_list->count; i++)
128    {
129        screen_list->screen[i]->visible = 0;
130        screen_list->screen[i]->x = 1;
131        screen_list->screen[i]->y = 1;
132
133        resize_screen(screen_list->screen[i],
134                      w, h);
135    }
136    screen_list->screen[screen_list->pty]->visible = 1;
137}
138
139
140void update_windows_props_cards(struct screen_list *screen_list)
141{
142    int i;
143    int w = (screen_list->width  - screen_list->count*3) + 1;
144    int h = (screen_list->height - screen_list->count) - 1;
145    int x = 1;
146    int y = screen_list->count;
147
148    for(i = 0; i < screen_list->count; i++)
149    {
150        screen_list->screen[i]->visible = 1;
151        screen_list->screen[i]->x = x;
152        screen_list->screen[i]->y = y;
153
154        resize_screen(screen_list->screen[i],
155                      w, h);
156        x += 3;
157        y--;
158    }
159}
160
Note: See TracBrowser for help on using the repository browser.