Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
xembed.cc
Go to the documentation of this file.
1/*
2 * File: xembed.cc
3 *
4 * Copyright (C) 2009 Jorge Arellano Cid <jcid@dillo.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <string.h>
13#include <ctype.h>
14
15#define FL_INTERNALS
16#include <FL/Fl_Window.H>
17#include <FL/Fl.H>
18
19#include "xembed.hh"
20
21#if !( defined(DISABLE_XEMBED) || defined(WIN32) || defined(__APPLE__) )
22#include <FL/x.H>
23
38
39void
40Xembed::setXembedInfo(unsigned long flags)
41{
42 unsigned long buffer[2];
43
44 Atom xembed_info_atom = XInternAtom (fl_display, "_XEMBED_INFO", false);
45
46 buffer[0] = 1;
47 buffer[1] = flags;
48
49 XChangeProperty (fl_display,
50 xid,
51 xembed_info_atom, xembed_info_atom, 32,
52 PropModeReplace,
53 (unsigned char *)buffer, 2);
54}
55
56void
57Xembed::sendXembedEvent(uint32_t message) {
58 XClientMessageEvent xclient;
59
60 memset (&xclient, 0, sizeof (xclient));
61 xclient.window = xid;
62 xclient.type = ClientMessage;
63 xclient.message_type = XInternAtom (fl_display, "_XEMBED", false);
64 xclient.format = 32;
65 xclient.data.l[0] = fl_event_time;
66 xclient.data.l[1] = message;
67
68 XSendEvent(fl_display, xid, False, NoEventMask, (XEvent *)&xclient);
69 XSync(fl_display, False);
70}
71
72int
74 if (e == FL_PUSH)
76
77 return Fl_Window::handle(e);
78}
79
80static int event_handler(int e, Fl_Window *w) {
81 Atom xembed_atom = XInternAtom (fl_display, "_XEMBED", false);
82
83 if (fl_xevent->type == ClientMessage) {
84 if (fl_xevent->xclient.message_type == xembed_atom) {
85 long message = fl_xevent->xclient.data.l[1];
86
87 switch (message) {
89 // Force a ConfigureNotify message so fltk can get the new
90 // coordinates after a move of the embedder window.
91 if (w)
92 w->resize(0,0, w->w(), w->h());
93 break;
95 break;
96 default:
97 break;
98 }
99 }
100 }
101
102 return Fl::handle_(e, w);
103}
104
105// TODO: Implement more XEMBED support;
106
109 setXembedInfo(1);
110 Fl::event_dispatch(event_handler);
111 Fl_Window::show();
112}
113
114void Xembed::createInternal(uint32_t parent) {
115 Fl_Window *window = this;
116 Colormap colormap = fl_colormap;
117
118 XSetWindowAttributes attr;
119 attr.border_pixel = 0;
120 attr.colormap = colormap;
121 attr.bit_gravity = 0; // StaticGravity;
122 int mask = CWBorderPixel|CWColormap|CWEventMask|CWBitGravity;
123
124 int W = window->w();
125 if (W <= 0) W = 1; // X don't like zero...
126 int H = window->h();
127 if (H <= 0) H = 1; // X don't like zero...
128 int X = window->x();
129 int Y = window->y();
130
131 attr.event_mask =
132 ExposureMask | StructureNotifyMask
133 | KeyPressMask | KeyReleaseMask | KeymapStateMask | FocusChangeMask
134 | ButtonPressMask | ButtonReleaseMask
135 | EnterWindowMask | LeaveWindowMask
136 | PointerMotionMask;
137
138 Fl_X::set_xid(window,
139 XCreateWindow(fl_display,
140 parent,
141 X, Y, W, H,
142 0, // borderwidth
143 fl_visual->depth,
144 InputOutput,
145 fl_visual->visual,
146 mask, &attr));
147}
148
149#else // X_PROTOCOL
150
151void
152Xembed::setXembedInfo(unsigned long flags) {};
153
154void
155Xembed::sendXembedEvent(uint32_t message) {};
156
157int
158Xembed::handle(int e) {
159 return Fl_Window::handle(e);
160}
161
162void
163Xembed::show() {
164 Fl_Window::show();
165}
166
167#endif
uint32_t xid
Definition xembed.hh:10
void sendXembedEvent(uint32_t message)
Definition xembed.cc:57
void setXembedInfo(unsigned long flags)
Definition xembed.cc:40
void show()
Definition xembed.cc:107
int handle(int event)
Definition xembed.cc:73
void createInternal(uint32_t parent)
Definition xembed.cc:114
static Fl_Window * window
#define H(x, y, z)
static int event_handler(int e, Fl_Window *w)
Definition xembed.cc:80
XEmbedMessageType
Definition xembed.cc:24
@ XEMBED_REQUEST_FOCUS
Definition xembed.cc:28
@ XEMBED_WINDOW_DEACTIVATE
Definition xembed.cc:27
@ XEMBED_FOCUS_OUT
Definition xembed.cc:30
@ XEMBED_GRAB_KEY
Definition xembed.cc:33
@ XEMBED_MODALITY_OFF
Definition xembed.cc:36
@ XEMBED_FOCUS_IN
Definition xembed.cc:29
@ XEMBED_MODALITY_ON
Definition xembed.cc:35
@ XEMBED_WINDOW_ACTIVATE
Definition xembed.cc:26
@ XEMBED_FOCUS_NEXT
Definition xembed.cc:31
@ XEMBED_FOCUS_PREV
Definition xembed.cc:32
@ XEMBED_EMBEDDED_NOTIFY
Definition xembed.cc:25
@ XEMBED_UNGRAB_KEY
Definition xembed.cc:34