aboutsummaryrefslogtreecommitdiff
path: root/src/Xutil.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xutil.cc')
-rw-r--r--src/Xutil.cc83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/Xutil.cc b/src/Xutil.cc
new file mode 100644
index 0000000..671c52e
--- /dev/null
+++ b/src/Xutil.cc
@@ -0,0 +1,83 @@
1// Xutil.cc for Fluxbox - an X11 Window manager
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net)
3// and Simon Bowden (rathnor at users.sourceforge.net)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
22
23// $Id: Xutil.cc,v 1.2 2003/10/02 16:14:41 rathnor Exp $
24
25#include "Xutil.hh"
26
27#include "I18n.hh"
28#include "App.hh"
29
30#include <X11/Xutil.h>
31#include <X11/Xatom.h>
32#include <X11/Xlib.h>
33
34namespace Xutil {
35
36std::string getWMName(Window window) {
37
38 if (window == None)
39 return "";
40
41 Display *display = FbTk::App::instance()->display();
42
43 XTextProperty text_prop;
44 text_prop.value = 0;
45 char **list;
46 int num;
47 I18n *i18n = I18n::instance();
48 std::string name;
49
50 if (XGetWMName(display, window, &text_prop)) {
51 if (text_prop.value && text_prop.nitems > 0) {
52 if (text_prop.encoding != XA_STRING) {
53
54 text_prop.nitems = strlen((char *) text_prop.value);
55
56 if ((XmbTextPropertyToTextList(display, &text_prop,
57 &list, &num) == Success) &&
58 (num > 0) && *list) {
59 name = static_cast<char *>(*list);
60 XFreeStringList(list);
61 } else
62 name = text_prop.value ? (char *)text_prop.value : "";
63
64 } else
65 name = text_prop.value ? (char *)text_prop.value : "";
66
67 XFree(text_prop.value);
68
69 } else { // default name
70 name = i18n->getMessage(FBNLS::WindowSet, FBNLS::WindowUnnamed,
71 "Unnamed");
72 }
73 } else {
74 // default name
75 name = i18n->getMessage(FBNLS::WindowSet, FBNLS::WindowUnnamed,
76 "Unnamed");
77 }
78
79 return name;
80}
81
82}; // end namespace Xutil
83