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

Last change on this file since 3460 was 3460, checked in by Pascal Terjan, 11 years ago
  • Mark screen as changed when it gets resized even if resize/add/remove will trigger a full redraw
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_free_canvas(old);
43    set_tty_size(s->fd, w, h);
44
45    s->orig_w = s->w;
46    s->orig_h = s->h;
47    s->orig_x = s->x;
48    s->orig_y = s->y;
49}
50
51void update_windows_props(struct screen_list *screen_list)
52{
53    if(!screen_list->count) return;
54
55    switch(screen_list->wm_type)
56    {
57    case WM_CARD:
58        update_windows_props_cards(screen_list);
59        break;
60    case WM_HSPLIT:
61        update_windows_props_hsplit(screen_list);
62        break;
63    case WM_VSPLIT:
64        update_windows_props_vsplit(screen_list);
65        break;
66    case WM_FULL:
67    default:
68        update_windows_props_full(screen_list);
69        break;
70    }
71}
72
73void update_windows_props_hsplit(struct screen_list *screen_list)
74{
75    int i;
76    int w = (screen_list->width / screen_list->count) - 1;
77    int h = (screen_list->height) - 2;
78
79    for(i = 0; i < screen_list->count; i++)
80    {
81        screen_list->screen[i]->x = (i*w)+1;
82        screen_list->screen[i]->y = 1;
83        screen_list->screen[i]->visible = 1;
84        if(i != screen_list->count -1)
85        {
86            resize_screen(screen_list->screen[i],
87                          w - 1, h);
88        } else {
89            resize_screen(screen_list->screen[i],
90                          screen_list->width - i*w - 1,
91                          h);
92        }
93    }
94}
95
96void update_windows_props_vsplit(struct screen_list *screen_list)
97{
98    int i;
99    int w = screen_list->width - 2;
100    int h = (screen_list->height / screen_list->count);
101
102    for(i = 0; i < screen_list->count; i++)
103    {
104        screen_list->screen[i]->x = 1;
105        screen_list->screen[i]->y = (i*h) + 1;
106        screen_list->screen[i]->visible = 1;
107        if(i != screen_list->count -1)
108        {
109            resize_screen(screen_list->screen[i],
110                          w, h - 2);
111        } else {
112            resize_screen(screen_list->screen[i],
113                          w,
114                          screen_list->height - i*h - 2);
115        }
116    }
117}
118
119
120void update_windows_props_full(struct screen_list *screen_list)
121{
122    int i;
123    int w = screen_list->width - 2;
124    int h = screen_list->height - 2;
125
126    for(i = 0; i < screen_list->count; i++)
127    {
128        screen_list->screen[i]->visible = 0;
129        screen_list->screen[i]->x = 1;
130        screen_list->screen[i]->y = 1;
131
132        resize_screen(screen_list->screen[i],
133                      w, h);
134    }
135    screen_list->screen[screen_list->pty]->visible = 1;
136}
137
138
139void update_windows_props_cards(struct screen_list *screen_list)
140{
141    int i;
142    int w = (screen_list->width  - screen_list->count) - 3;
143    int h = (screen_list->height - screen_list->count) - 4;
144    int x = (screen_list->width  - w) - (3*screen_list->count) + 4;
145    int y = 2 + (1*screen_list->count);
146
147    for(i = 0; i < screen_list->count; i++)
148    {
149        screen_list->screen[i]->visible = 1;
150        screen_list->screen[i]->x = x;
151        screen_list->screen[i]->y = y;
152
153        resize_screen(screen_list->screen[i],
154                      w, h);
155        x += 3;
156        y--;
157    }
158}
159
Note: See TracBrowser for help on using the repository browser.