aboutsummaryrefslogtreecommitdiffstats
path: root/matchbox/client-types/mb-wm-client-note.c
blob: d0bb770caa2457bae2efc566a7411b94c0ecbb60 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
 *  Matchbox Window Manager II - A lightweight window manager not for the
 *                               desktop.
 *
 *  Authored By Tomas Frydrych <tf@o-hand.com>
 *
 *  Copyright (c) 2007 OpenedHand Ltd - http://o-hand.com
 *
 *  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, 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.
 *
 */

#include "mb-wm-client-note.h"

#include "mb-wm-theme.h"

static void
mb_wm_client_note_class_init (MBWMObjectClass *klass)
{
  MBWindowManagerClientClass *client;

  MBWM_MARK();

  client = (MBWindowManagerClientClass *)klass;

  client->client_type  = MBWMClientTypeNote;

#if MBWM_WANT_DEBUG
  klass->klass_name = "MBWMClientNote";
#endif
}

static void
mb_wm_client_note_destroy (MBWMObject *this)
{
}

static int
mb_wm_client_note_init (MBWMObject *this, va_list vap)
{
  MBWindowManagerClient *client = MB_WM_CLIENT (this);
  MBWindowManager       *wm = client->wmref;
  MBWMClientWindow      *win = client->window;
  MBGeometry             geom;
  Bool                   change = False;
  Atom actions[] = {
    wm->atoms[MBWM_ATOM_NET_WM_ACTION_CLOSE],
    wm->atoms[MBWM_ATOM_NET_WM_ACTION_MOVE],
  };

  geom = client->frame_geometry;

  if (geom.x >= wm->xdpy_width)
    {
      geom.x = wm->xdpy_width - geom.width;
      change = True;
    }

  if (geom.y >= wm->xdpy_height)
    {
      geom.y = wm->xdpy_height - geom.height;
      change = True;
    }

  switch (win->gravity)
    {
    case SouthGravity:
      geom.y = wm->xdpy_height - geom.height;
      change = True;
      break;
    case EastGravity:
      geom.x = wm->xdpy_width - geom.width;
      change = True;
      break;
    case SouthEastGravity:
      geom.y = wm->xdpy_height - geom.height;
      geom.x = wm->xdpy_width - geom.width;
      change = True;
      break;
    case NorthGravity:
      geom.y = 0;
      change = True;
      break;
    case WestGravity:
      geom.x = 0;
      change = True;
      break;
    case NorthWestGravity:
    case CenterGravity:
    case StaticGravity:
    default:
      ;
    }

  if (change)
    {
      mb_wm_client_request_geometry (client, &geom, MBWMClientReqGeomForced);
      mb_wm_client_geometry_mark_dirty (client);
    }


  XChangeProperty (wm->xdpy, win->xwindow,
		   wm->atoms[MBWM_ATOM_NET_WM_ALLOWED_ACTIONS],
		   XA_ATOM, 32, PropModeReplace,
		   (unsigned char *)actions,
		   sizeof (actions)/sizeof (actions[0]));

  return 1;
}

int
mb_wm_client_note_class_type ()
{
  static int type = 0;

  if (UNLIKELY(type == 0))
    {
      static MBWMObjectClassInfo info = {
	sizeof (MBWMClientNoteClass),
	sizeof (MBWMClientNote),
	mb_wm_client_note_init,
	mb_wm_client_note_destroy,
	mb_wm_client_note_class_init
      };

      type = mb_wm_object_register_class (&info, MB_WM_TYPE_CLIENT_DIALOG, 0);
    }

  return type;
}

MBWindowManagerClient*
mb_wm_client_note_new (MBWindowManager *wm, MBWMClientWindow *win)
{
  MBWindowManagerClient *client;

  client
    = MB_WM_CLIENT (mb_wm_object_new (MB_WM_TYPE_CLIENT_NOTE,
				      MBWMObjectPropWm,           wm,
				      MBWMObjectPropClientWindow, win,
				      NULL));

  return client;
}