summaryrefslogtreecommitdiff
path: root/openbox/per_app_settings.c
blob: 47b2fc0ec188666c99b792feda97cc7cb0b305a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-

   client.h for the Openbox window manager
   Copyright (c) 2006        Mikael Magnusson

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   See the COPYING file for a copy of the GNU General Public License.
*/

#include "per_app_settings.h"
#include "screen.h"

GSList *per_app_settings;

ObAppSetting *get_client_settings(ObClient *client)
{
    GSList *a = per_app_settings;

    while (a) {
        ObAppSetting *app = (ObAppSetting *) a->data;
        
        if (!strcmp(app->name, client->name)) {
            ob_debug("Window matching: %s\n", app->name);

            return (ObAppSetting *) a->data;
        }

        a = a->next;
    }
    return NULL;
}

void place_window_from_settings(ObAppSetting *setting, ObClient *client, gint *x, gint *y)
{
    gint px, py, i;
    Rect *screen;

    /* Find which head the pointer is on, partly taken from place.c */
    if (setting->head == -1) {
        screen_pointer_pos(&px, &py);

        for (i = 0; i < screen_num_monitors; i++) {
            screen = screen_area_monitor(client->desktop, i);
            if (RECT_CONTAINS(*screen, px, py))
                break;
        }

        if (i == screen_num_monitors)
            screen = screen_area_monitor(client->desktop, 0);
    }
    else
        screen = screen_area_monitor(client->desktop, setting->head);

    if (setting->position.x == -1 && setting->center_x)
        *x = screen->x + screen->width / 2 - client->area.width / 2;
    else if (setting->position.x != -1)
        *x = screen->x + setting->position.x;

    if (setting->position.y == -1 && setting->center_y)
        *y = screen->y + screen->height / 2 - client->area.height / 2;
    else if (setting->position.y != -1)
        *y = screen->y + setting->position.y;

}