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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
/***************************************************************************
* Copyright (C) 2002~2005 by Yuking *
* yuking_net@sohu.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 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. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include <string.h>
#include <stdlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <libintl.h>
#include "fcitx/ui.h"
#include "fcitx/module.h"
#include "fcitx/profile.h"
#include "fcitx/frontend.h"
#include "fcitx/configfile.h"
#include "fcitx/instance.h"
#include "fcitx-utils/utils.h"
#include "InputWindow.h"
#include "lightui.h"
#include "draw.h"
#include <fcitx/module/x11/x11stuff.h>
#include "MainWindow.h"
#include <fcitx-utils/log.h>
static boolean InputWindowEventHandler(void *arg, XEvent* event);
static void InitInputWindow(InputWindow* inputWindow);
static void ReloadInputWindow(void* arg, boolean enabled);
void InitInputWindow(InputWindow* inputWindow)
{
XSetWindowAttributes attrib;
unsigned long attribmask;
char strWindowName[]="Fcitx Input Window";
int depth;
Colormap cmap;
Visual * vs;
FcitxLightUI* lightui = inputWindow->owner;
int iScreen = lightui->iScreen;
Display* dpy = lightui->dpy;
inputWindow->window = None;
inputWindow->iInputWindowHeight = INPUTWND_HEIGHT;
inputWindow->iInputWindowWidth = INPUTWND_WIDTH;
inputWindow->iOffsetX = 0;
inputWindow->iOffsetY = 8;
inputWindow->dpy = dpy;
inputWindow->iScreen = iScreen;
inputWindow->iInputWindowHeight= INPUTWND_HEIGHT;
vs= NULL;
LightUIInitWindowAttribute(lightui, &vs, &cmap, &attrib, &attribmask, &depth);
inputWindow->window=XCreateWindow (dpy,
RootWindow(dpy, iScreen),
lightui->iMainWindowOffsetX,
lightui->iMainWindowOffsetY,
inputWindow->iInputWindowWidth,
inputWindow->iInputWindowHeight,
0,
depth,InputOutput,
vs,attribmask,
&attrib);
inputWindow->pixmap = XCreatePixmap(dpy,
inputWindow->window,
INPUT_BAR_MAX_WIDTH,
INPUT_BAR_MAX_HEIGHT,
depth);
inputWindow->pixmap2 = XCreatePixmap(dpy,
inputWindow->pixmap,
INPUT_BAR_MAX_WIDTH,
INPUT_BAR_MAX_HEIGHT,
depth);
XGCValues gcvalues;
inputWindow->window_gc = XCreateGC(inputWindow->dpy, inputWindow->window, 0, &gcvalues);
inputWindow->pixmap_gc = XCreateGC(inputWindow->dpy, inputWindow->pixmap, 0, &gcvalues);
inputWindow->pixmap2_gc = XCreateGC(inputWindow->dpy, inputWindow->pixmap2, 0, &gcvalues);
inputWindow->xftDraw = XftDrawCreate(inputWindow->dpy, inputWindow->pixmap, DefaultVisual (dpy, DefaultScreen (dpy)), DefaultColormap (dpy, DefaultScreen (dpy)));
XSelectInput (dpy, inputWindow->window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask);
LightUISetWindowProperty(lightui, inputWindow->window, FCITX_WINDOW_DOCK, strWindowName);
}
InputWindow* CreateInputWindow(FcitxLightUI *lightui)
{
InputWindow* inputWindow;
inputWindow = fcitx_utils_malloc0(sizeof(InputWindow));
inputWindow->owner = lightui;
InitInputWindow(inputWindow);
FcitxModuleFunctionArg arg;
arg.args[0] = InputWindowEventHandler;
arg.args[1] = inputWindow;
InvokeFunction(lightui->owner, FCITX_X11, ADDXEVENTHANDLER, arg);
arg.args[0] = ReloadInputWindow;
arg.args[1] = inputWindow;
InvokeFunction(lightui->owner, FCITX_X11, ADDCOMPOSITEHANDLER, arg);
inputWindow->msgUp = FcitxMessagesNew();
inputWindow->msgDown = FcitxMessagesNew();
return inputWindow;
}
boolean InputWindowEventHandler(void *arg, XEvent* event)
{
InputWindow* inputWindow = arg;
if (event->xany.window == inputWindow->window)
{
switch (event->type)
{
case Expose:
DrawInputWindow(inputWindow);
break;
case ButtonPress:
switch (event->xbutton.button) {
case Button1:
{
int x,
y;
x = event->xbutton.x;
y = event->xbutton.y;
LightUIMouseClick(inputWindow->owner, inputWindow->window, &x, &y);
FcitxInputContext* ic = FcitxInstanceGetCurrentIC(inputWindow->owner->owner);
if (ic)
FcitxInstanceSetWindowOffset(inputWindow->owner->owner, ic, x, y);
DrawInputWindow(inputWindow);
}
break;
}
break;
}
return true;
}
return false;
}
void DisplayInputWindow (InputWindow* inputWindow)
{
FcitxLog(DEBUG, _("DISPLAY InputWindow"));
MoveInputWindowInternal(inputWindow);
XMapRaised (inputWindow->dpy, inputWindow->window);
}
void DrawInputWindow(InputWindow* inputWindow)
{
int lastW = inputWindow->iInputWindowWidth, lastH = inputWindow->iInputWindowHeight;
int cursorPos = FcitxUINewMessageToOldStyleMessage(inputWindow->owner->owner, inputWindow->msgUp, inputWindow->msgDown);
DrawInputBar(inputWindow, cursorPos, inputWindow->msgUp, inputWindow->msgDown, &inputWindow->iInputWindowHeight ,&inputWindow->iInputWindowWidth);
/* Resize Window will produce Expose Event, so there is no need to draw right now */
if (lastW != inputWindow->iInputWindowWidth || lastH != inputWindow->iInputWindowHeight)
{
XResizeWindow(
inputWindow->dpy,
inputWindow->window,
inputWindow->iInputWindowWidth,
inputWindow->iInputWindowHeight);
MoveInputWindowInternal(inputWindow);
}
XCopyArea(
inputWindow->dpy,
inputWindow->pixmap,
inputWindow->window,
inputWindow->window_gc,
0, 0,
inputWindow->iInputWindowWidth,
inputWindow->iInputWindowHeight,
0, 0
);
XFlush(inputWindow->dpy);
}
void MoveInputWindowInternal(InputWindow* inputWindow)
{
int dwidth, dheight;
int x = 0, y = 0;
GetScreenSize(inputWindow->owner, &dwidth, &dheight);
FcitxInputContext* ic = FcitxInstanceGetCurrentIC(inputWindow->owner->owner);
FcitxInstanceGetWindowPosition(inputWindow->owner->owner, ic, &x, &y);
int iTempInputWindowX, iTempInputWindowY;
if (x < 0)
iTempInputWindowX = 0;
else
iTempInputWindowX = x + inputWindow->iOffsetX;
if (y < 0)
iTempInputWindowY = 0;
else
iTempInputWindowY = y + inputWindow->iOffsetY;
if ((iTempInputWindowX + inputWindow->iInputWindowWidth) > dwidth)
iTempInputWindowX = dwidth - inputWindow->iInputWindowWidth;
if ((iTempInputWindowY + inputWindow->iInputWindowHeight) > dheight) {
if ( iTempInputWindowY > dheight )
iTempInputWindowY = dheight - 2 * inputWindow->iInputWindowHeight;
else
iTempInputWindowY = iTempInputWindowY - 2 * inputWindow->iInputWindowHeight;
}
XMoveWindow (inputWindow->dpy, inputWindow->window, iTempInputWindowX, iTempInputWindowY);
}
void CloseInputWindowInternal(InputWindow* inputWindow)
{
XUnmapWindow (inputWindow->dpy, inputWindow->window);
}
void ReloadInputWindow(void* arg, boolean enabled)
{
InputWindow* inputWindow = (InputWindow*) arg;
boolean visable = WindowIsVisable(inputWindow->dpy, inputWindow->window);
XFreeGC(inputWindow->dpy, inputWindow->window_gc);
XFreeGC(inputWindow->dpy, inputWindow->pixmap_gc);
XFreeGC(inputWindow->dpy, inputWindow->pixmap2_gc);
XFreePixmap(inputWindow->dpy, inputWindow->pixmap2);
XFreePixmap(inputWindow->dpy, inputWindow->pixmap);
XDestroyWindow(inputWindow->dpy, inputWindow->window);
XftDrawDestroy(inputWindow->xftDraw);
inputWindow->window = None;
InitInputWindow(inputWindow);
if (visable)
ShowInputWindowInternal(inputWindow);
}
void ShowInputWindowInternal(InputWindow* inputWindow)
{
XMapRaised(inputWindow->dpy, inputWindow->window);
DrawInputWindow(inputWindow);
}
// kate: indent-mode cstyle; space-indent on; indent-width 0;
|