| 1 |
/* |
| 2 |
* Copyright (c) 2001 Marcin Dalecki |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 |
* of this software and associated documentation files (the "Software"), to |
| 6 |
* deal in the Software without restriction, including without limitation the |
| 7 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 8 |
* sell copies of the Software, and to permit persons to whom the Software is |
| 9 |
* furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included in |
| 12 |
* all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY CLAIM, |
| 18 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
* |
| 22 |
*/ |
| 23 |
|
| 24 |
/* |
| 25 |
* Implement a nice and well behaved application icon. |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "xdvi-config.h" |
| 29 |
#include "xdvi.h" |
| 30 |
#include "xicon.h" |
| 31 |
#include "util.h" |
| 32 |
#include "xdvi-debug.h" |
| 33 |
|
| 34 |
#include <X11/X.h> |
| 35 |
#include <X11/Xlib.h> |
| 36 |
#include <X11/Xutil.h> |
| 37 |
#include <X11/Xos.h> |
| 38 |
#include <X11/Xfuncs.h> |
| 39 |
#include <X11/Intrinsic.h> |
| 40 |
#include <X11/StringDefs.h> |
| 41 |
#include <X11/Shell.h> |
| 42 |
|
| 43 |
#ifdef MOTIF |
| 44 |
# include <Xm/XmStrDefs.h> |
| 45 |
#endif |
| 46 |
|
| 47 |
#if defined(HAVE_X11_XPM_H) |
| 48 |
# include <X11/xpm.h> |
| 49 |
#elif defined(HAVE_XPM_H) |
| 50 |
# include <xpm.h> |
| 51 |
#elif defined(HAVE_XM_XPMP_H) |
| 52 |
# include <Xm/XpmP.h> |
| 53 |
#endif |
| 54 |
|
| 55 |
#include "xdvi.icon" |
| 56 |
#include "pixmaps/xdvi32x32.xpm" |
| 57 |
#include "pixmaps/xdvi16x16.xpm" |
| 58 |
#include "pixmaps/xdvi48x48.xpm" |
| 59 |
void |
| 60 |
add_icon(Widget top_level, |
| 61 |
String title_name, |
| 62 |
String icon_name) |
| 63 |
{ |
| 64 |
#if !HAVE_XPM |
| 65 |
|
| 66 |
static Arg args[] = { |
| 67 |
{XtNiconX, (XtArgVal) 0}, |
| 68 |
{XtNiconY, (XtArgVal) 0}, |
| 69 |
}; |
| 70 |
static Pixmap icon_pm; |
| 71 |
static Arg temp_args4 = { XtNiconPixmap, (XtArgVal) &icon_pm }; |
| 72 |
|
| 73 |
UNUSED(xdvi16x16_xpm); |
| 74 |
UNUSED(xdvi32x32_xpm); |
| 75 |
UNUSED(xdvi48x48_xpm); |
| 76 |
|
| 77 |
if (resource.icon_geometry != NULL) { |
| 78 |
int junk; |
| 79 |
|
| 80 |
(void)XGeometry(DISP, XScreenNumberOfScreen(SCRN), |
| 81 |
resource.icon_geometry, "", |
| 82 |
0, 0, 0, 0, 0, |
| 83 |
(int *)&args[0].value, |
| 84 |
(int *)&args[1].value, |
| 85 |
&junk, |
| 86 |
&junk); |
| 87 |
XtSetValues(top_level, args, XtNumber(args)); |
| 88 |
} |
| 89 |
/* Set icon pixmap */ |
| 90 |
XtGetValues(top_level, &temp_args4, 1); |
| 91 |
if (icon_pm == (Pixmap) 0) { |
| 92 |
temp_args4.value = |
| 93 |
(XtArgVal)XCreateBitmapFromData(DISP, |
| 94 |
RootWindowOfScreen(SCRN), |
| 95 |
(const char *)xdvi_bits, |
| 96 |
xdvi_width, |
| 97 |
xdvi_height); |
| 98 |
XtSetValues(top_level, &temp_args4, 1); |
| 99 |
} |
| 100 |
#else /* HAVE_XPM */ |
| 101 |
|
| 102 |
/* Use Pixmaps, looking much nicer. */ |
| 103 |
|
| 104 |
static Pixmap icon = 0; |
| 105 |
static Pixmap icon_mask = 0; |
| 106 |
static const char **pixmap_data = xdvi32x32_xpm; |
| 107 |
XIconSize *size; |
| 108 |
int number_sizes; |
| 109 |
Display *dsp; |
| 110 |
XpmAttributes attr; |
| 111 |
|
| 112 |
UNUSED(xdvi_bits); |
| 113 |
/* |
| 114 |
* get the icon size preferred by the window manager |
| 115 |
*/ |
| 116 |
if (XGetIconSizes(XtDisplay(top_level), RootWindowOfScreen(SCRN), |
| 117 |
&size, &number_sizes) != 0) { |
| 118 |
if (number_sizes > 0) { |
| 119 |
if (size->max_height >= 48 && size->max_height >= 48) |
| 120 |
pixmap_data = xdvi48x48_xpm; |
| 121 |
else if (size->max_height >= 32 && size->max_height >= 32) |
| 122 |
pixmap_data = xdvi32x32_xpm; |
| 123 |
else if (size->max_height >= 16 && size->max_height >= 16) |
| 124 |
pixmap_data = xdvi16x16_xpm; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
dsp = XtDisplay(top_level); |
| 129 |
|
| 130 |
attr.valuemask = 0L; |
| 131 |
attr.valuemask = XpmCloseness | XpmReturnPixels | XpmColormap | XpmDepth | XpmVisual; |
| 132 |
attr.closeness = 65535; /* accuracy isn't crucial */ |
| 133 |
/* use the same visual/colormap/depth as main window, else BadMatch ... */ |
| 134 |
attr.visual = G_visual; |
| 135 |
attr.colormap = G_colormap; |
| 136 |
attr.depth = G_depth; |
| 137 |
|
| 138 |
if (!icon) { |
| 139 |
Window rootWindow = XtWindow(globals.widgets.top_level); |
| 140 |
ASSERT(rootWindow != 0, ""); |
| 141 |
XpmCreatePixmapFromData(dsp, rootWindow, (char **)pixmap_data, |
| 142 |
&icon, &icon_mask, &attr); |
| 143 |
} |
| 144 |
|
| 145 |
# ifdef MOTIF |
| 146 |
XtVaSetValues(top_level, XmNiconPixmap, icon, XmNiconMask, icon_mask, NULL); |
| 147 |
# else |
| 148 |
XtVaSetValues(top_level, XtNiconPixmap, icon, XtNiconMask, icon_mask, NULL); |
| 149 |
# endif |
| 150 |
|
| 151 |
XpmFreeAttributes(&attr); |
| 152 |
#endif |
| 153 |
|
| 154 |
{ |
| 155 |
/* code locality ... */ |
| 156 |
static Arg args[] = { |
| 157 |
{ XtNtitle, (XtArgVal) 0 }, |
| 158 |
{ XtNiconName, (XtArgVal) 0 }, |
| 159 |
{ XtNinput, (XtArgVal) True }, |
| 160 |
}; |
| 161 |
|
| 162 |
args[0].value = (XtArgVal)title_name; |
| 163 |
args[1].value = (XtArgVal)icon_name; |
| 164 |
XtSetValues(top_level, args, XtNumber(args)); |
| 165 |
} |
| 166 |
} |