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

Last change on this file since 2367 was 2367, checked in by Jean-Yves Lamoureux, 12 years ago
  • Added a status bar and an help screen
File size: 3.4 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
44void update_windows_props(cucul_canvas_t *cv, struct screen_list *screen_list, int pty)
45{
46    switch(screen_list->wm_type)
47    {
48    case WM_CARD:
49        update_windows_props_cards(cv, screen_list, pty);
50        break;
51    case WM_HSPLIT:
52        update_windows_props_hsplit(cv, screen_list, pty);
53        break;
54    case WM_VSPLIT:
55        update_windows_props_vsplit(cv, screen_list, pty);
56        break;
57    case WM_FULL:
58    default:
59        update_windows_props_full(cv, screen_list, pty);
60        break;
61    }
62}
63
64void update_windows_props_hsplit(cucul_canvas_t *cv, struct screen_list *screen_list, int pty)
65{
66    int i;
67    int w = (screen_list->width / screen_list->count);
68    int h = (screen_list->height) - 2;
69
70
71    for(i = 0; i < screen_list->count; i++)
72    {
73        screen_list->screen[i]->x = (i*w)+1;
74        screen_list->screen[i]->y = 1;
75
76        resize_screen(screen_list->screen[i],
77                      w - 1, h);
78    }
79}
80
81void update_windows_props_vsplit(cucul_canvas_t *cv, struct screen_list *screen_list, int pty)
82{
83    int i;
84    int w = screen_list->width - 2;
85    int h = (screen_list->height / screen_list->count);
86
87    for(i = 0; i < screen_list->count; i++)
88    {
89        screen_list->screen[i]->x = 1;
90        screen_list->screen[i]->y = (i*h) + 1;
91
92        resize_screen(screen_list->screen[i],
93                      w, h - 1);
94    }
95}
96
97
98void update_windows_props_full(cucul_canvas_t *cv, struct screen_list *screen_list, int pty)
99{
100    int i;
101    int w = screen_list->width - 2;
102    int h = screen_list->height - 2;
103
104    for(i = 0; i < screen_list->count; i++)
105    {
106        screen_list->screen[i]->x = 1;
107        screen_list->screen[i]->y = 1;
108
109        resize_screen(screen_list->screen[i],
110                      w, h);
111    }
112}
113
114
115void update_windows_props_cards(cucul_canvas_t *cv, struct screen_list *screen_list, int pty)
116{
117    int i;
118    int w = (screen_list->width  - screen_list->count) - 3;
119    int h = (screen_list->height - screen_list->count) - 4;
120    int x = (screen_list->width  - w) - (3*screen_list->count) + 4;
121    int y = 2 + (1*screen_list->count);
122
123    for(i = 0; i < screen_list->count; i++)
124    {
125        screen_list->screen[i]->x = x;
126        screen_list->screen[i]->y = y;
127
128        resize_screen(screen_list->screen[i],
129                      w, h);
130        x += 3;
131        y--;
132    }
133}
134
Note: See TracBrowser for help on using the repository browser.