Jabber WindowGram Client (JWGC)

Introduction Screenshots Installation Downloads
Documentation Browse Source Resources Project Site

Stable Version
-none-

Latest Version
beta5



Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

xcut.c File Reference

#include "mit-copyright.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "new_string.h"
#include "X_gram.h"
#include "main.h"
#include "xselect.h"
#include "xmark.h"
#include "error.h"
#include "xrevstack.h"

Go to the source code of this file.

Defines

#define PRESSOP_NONE   0
#define PRESSOP_KILL   1
#define PRESSOP_SEL   2
#define PRESSOP_EXT   3
#define PRESSOP_NUKE   4
#define PRESSOP_STOP   5

Functions

char * xmarkGetText ()
char * getSelectedText ()
Bool isShiftButton1 (Display *dpy, XEvent *event, char *arg)
Bool isShiftButton3 (Display *dpy, XEvent *event, char *arg)
void getLastEvent (Display *dpy, unsigned int state, XEvent *event)
void xunmark (Display *dpy, Window w, x_gram *gram, XContext desc_context)
void xdestroygram (Display *dpy, Window w, XContext desc_context, x_gram *gram)
void xcut (Display *dpy, XEvent *event, XContext desc_context)

Variables

long ttl


Define Documentation

#define PRESSOP_EXT   3
 

Definition at line 108 of file xcut.c.

#define PRESSOP_KILL   1
 

Definition at line 106 of file xcut.c.

Referenced by xcut().

#define PRESSOP_NONE   0
 

Definition at line 105 of file xcut.c.

#define PRESSOP_NUKE   4
 

Definition at line 109 of file xcut.c.

#define PRESSOP_SEL   2
 

Definition at line 107 of file xcut.c.

Referenced by xcut().

#define PRESSOP_STOP   5
 

Definition at line 110 of file xcut.c.


Function Documentation

void getLastEvent Display *  dpy,
unsigned int  state,
XEvent *  event
 

Definition at line 71 of file xcut.c.

References dpy, isShiftButton1(), isShiftButton3(), and NULL.

00075 {
00076         XEvent xev;
00077 
00078         if (state & Button1Mask) {
00079                 while (XCheckIfEvent(dpy, &xev, isShiftButton1, NULL))
00080                         *event = xev;
00081         }
00082         else if (state & Button3Mask) {
00083                 while (XCheckIfEvent(dpy, &xev, isShiftButton3, NULL))
00084                         *event = xev;
00085         }
00086 }

char* getSelectedText  ) 
 

Definition at line 41 of file xcut.c.

00042 {
00043         return (selected_text);
00044 }

Bool isShiftButton1 Display *  dpy,
XEvent *  event,
char *  arg
 

Definition at line 52 of file xcut.c.

Referenced by getLastEvent().

00056 {
00057         return (event->xbutton.state & (ShiftMask | Button1Mask));
00058 }

Bool isShiftButton3 Display *  dpy,
XEvent *  event,
char *  arg
 

Definition at line 62 of file xcut.c.

Referenced by getLastEvent().

00066 {
00067         return (event->xbutton.state & (ShiftMask | Button3Mask));
00068 }

void xcut Display *  dpy,
XEvent *  event,
XContext  desc_context
 

Definition at line 148 of file xcut.c.

References _x_gram::above, desc_context, dpy, ERROR, NULL, PRESSOP_KILL, PRESSOP_SEL, ttl, unlink_gram(), x_gram, xdestroygram(), xmarkExtendFromFirst(), xmarkExtendFromNearest(), xmarkGetText(), xmarkRedraw(), xmarkStart, xselGetOwnership(), xselOwnershipLost(), xselProcessSelection(), and xunmark().

00152 {
00153         x_gram *gram;
00154         Window w = event->xany.window;
00155         int changedbound;
00156 
00157         /*
00158          * If event is for a window that's not ours anymore (say we're
00159          * in the process of deleting it...), ignore it:
00160          */
00161         if (XFindContext(dpy, w, desc_context, (caddr_t *) & gram))
00162                 return;
00163 
00164         /*
00165          * Dispatch on the event type:
00166          */
00167         switch (event->type) {
00168                 case ClientMessage:
00169                         if ((event->xclient.message_type == XA_WM_PROTOCOLS) &&
00170                             (event->xclient.format == 32) &&
00171                           (event->xclient.data.l[0] == XA_WM_DELETE_WINDOW))
00172                                 xdestroygram(dpy, w, desc_context, gram);
00173                         break;
00174 
00175                 case MapNotify:
00176                         /*
00177                          * I don't like using the local time, but MapNotify
00178                          * events don't come with a timestamp, and there's no
00179                          * way to query the server
00180                          */
00181 
00182                         if (gram->can_die.tv_sec == 0) {
00183                                 gettimeofday(&(gram->can_die), NULL);
00184                                 gram->can_die.tv_sec += (int) (ttl / 1000);
00185                                 gram->can_die.tv_usec += (ttl % 1000) * 1000;
00186                         }
00187                         break;
00188 
00189                 case UnmapNotify:
00190                         unlink_gram(gram);
00191                         break;
00192 
00193                 case LeaveNotify:
00194                         if (current_pressop == PRESSOP_KILL ||
00195                             current_pressop == PRESSOP_NUKE)
00196                                 current_pressop = PRESSOP_STOP;
00197                         break;
00198 
00199                 case MotionNotify:
00200                         if (current_pressop == PRESSOP_SEL) {
00201                                 /* getLastEvent(dpy,Button1Mask,event); */
00202                                 changedbound = xmarkExtendFromFirst(gram, event->xmotion.x,
00203                                                           event->xmotion.y);
00204                                 xmarkRedraw(dpy, w, gram, changedbound);
00205                         }
00206                         else if (current_pressop == PRESSOP_EXT) {
00207                                 /* getLastEvent(dpy,Button3Mask,event); */
00208                                 changedbound = xmarkExtendFromNearest(gram, event->xmotion.x,
00209                                                           event->xmotion.y);
00210                                 xmarkRedraw(dpy, w, gram, changedbound);
00211                         }
00212                         break;
00213 
00214                 case ButtonPress:
00215                         if (current_pressop != PRESSOP_NONE) {
00216                                 current_pressop = PRESSOP_STOP;
00217                         }
00218                         else if ((event->xbutton.state) & ShiftMask) {
00219                                 if (event->xbutton.button == Button1) {
00220                                         if (selecting_in)
00221                                                 xunmark(dpy, selecting_in, NULL, desc_context);
00222                                         if (selected_text)
00223                                                 free(selected_text);
00224                                         selected_text = NULL;
00225                                         if (!xselGetOwnership(dpy, w, event->xbutton.time)) {
00226                                                 XBell(dpy, 0);
00227                                                 ERROR("Unable to get ownership of PRIMARY selection.\n");
00228                                                 selecting_in = 0;
00229                                                 current_pressop = PRESSOP_STOP;
00230                                         }
00231                                         else {
00232                                                 selecting_in = w;
00233                                                 xmarkStart(gram, event->xbutton.x, event->xbutton.y);
00234                                                 current_pressop = PRESSOP_SEL;
00235                                         }
00236                                 }
00237                                 else if ((event->xbutton.button == Button3) &&
00238                                          (w == selecting_in)) {
00239                                         if (selected_text)
00240                                                 free(selected_text);
00241                                         selected_text = NULL;
00242                                         changedbound = xmarkExtendFromNearest(gram, event->xbutton.x,
00243                                                           event->xbutton.y);
00244                                         xmarkRedraw(dpy, w, gram, changedbound);
00245                                         selected_text = xmarkGetText();
00246                                         /*
00247                                          * this is ok, since to get here, the
00248                                          * selection must be owned
00249                                          */
00250                                         current_pressop = PRESSOP_EXT;
00251                                 }
00252                         }
00253                         else if ((event->xbutton.state) & ControlMask) {
00254                                 current_pressop = PRESSOP_NUKE;
00255                         }
00256                         else {
00257                                 current_pressop = PRESSOP_KILL;
00258                         }
00259                         break;
00260 
00261                 case ButtonRelease:
00262                         if (current_pressop == PRESSOP_KILL) {
00263                                 xdestroygram(dpy, w, desc_context, gram);
00264                         }
00265                         else if (current_pressop == PRESSOP_SEL ||
00266                                  current_pressop == PRESSOP_EXT) {
00267                                 if (selected_text)
00268                                         free(selected_text);
00269                                 selected_text = xmarkGetText();
00270                         }
00271                         else if (current_pressop == PRESSOP_NUKE) {
00272                                 XWindowAttributes wa;
00273                                 int gx, gy;
00274                                 Window temp;
00275                                 x_gram *next;
00276 
00277                                 for (gram = bottom_gram; gram; gram = next) {
00278                                         XGetWindowAttributes(dpy, gram->w, &wa);
00279                                         XTranslateCoordinates(dpy, gram->w, wa.root, 0, 0, &gx, &gy,
00280                                                               &temp);
00281 
00282                                         next = gram->above;
00283 
00284                                         if ((wa.map_state == IsViewable) &&
00285                                             (gx <= event->xbutton.x_root) &&
00286                                             (event->xbutton.x_root < gx + wa.width) &&
00287                                             (gy <= event->xbutton.y_root) &&
00288                                             (event->xbutton.y_root < gy + wa.height)) {
00289                                                 xdestroygram(dpy, gram->w, desc_context, gram);
00290                                         }
00291                                 }
00292                                 for (gram = unlinked; gram; gram = next) {
00293                                         XGetWindowAttributes(dpy, gram->w, &wa);
00294                                         XTranslateCoordinates(dpy, gram->w, wa.root, 0, 0, &gx, &gy,
00295                                                               &temp);
00296 
00297                                         next = gram->above;
00298 
00299                                         if ((wa.map_state == IsViewable) &&
00300                                             (gx <= event->xbutton.x_root) &&
00301                                             (event->xbutton.x_root < gx + wa.width) &&
00302                                             (gy <= event->xbutton.y_root) &&
00303                                             (event->xbutton.y_root < gy + wa.height)) {
00304                                                 xdestroygram(dpy, gram->w, desc_context, gram);
00305                                         }
00306                                 }
00307                         }
00308                         current_pressop = PRESSOP_NONE;
00309                         break;
00310 
00311                 case SelectionRequest:
00312                         xselProcessSelection(dpy, w, event);
00313                         break;
00314 
00315                 case SelectionClear:
00316                         xselOwnershipLost(event->xselectionclear.time);
00317                         if (w == selecting_in) {
00318                                 selecting_in = 0;
00319                                 xunmark(dpy, w, gram, desc_context);
00320                                 if (selected_text)
00321                                         free(selected_text);
00322                                 selected_text = NULL;
00323                         }
00324                         break;
00325 
00326                 default:
00327                         break;
00328         }
00329 
00330         XFlush(dpy);
00331 }

void xdestroygram Display *  dpy,
Window  w,
XContext  desc_context,
x_gram gram
 

Definition at line 115 of file xcut.c.

References _x_gram::blocks, bottom_gram, _x_gram::can_die, delete_gram(), desc_context, dpy, NULL, _x_gram::text, unlinked, x_gram, and xmarkClear().

Referenced by xcut().

00120 {
00121         struct timeval now;
00122 
00123         gettimeofday(&now, NULL);
00124         if ((gram->can_die.tv_sec == 0) ||
00125             (gram->can_die.tv_sec > now.tv_sec) ||
00126             ((gram->can_die.tv_sec == now.tv_sec) &&
00127              (gram->can_die.tv_usec > now.tv_usec)))
00128                 return;
00129 
00130         if (w == selecting_in) {
00131                 selecting_in = 0;
00132                 xmarkClear();
00133         }
00134         current_pressop = PRESSOP_NONE;
00135         XDeleteContext(dpy, w, desc_context);
00136         XDestroyWindow(dpy, w);
00137         delete_gram(gram);
00138         free(gram->text);
00139         free(gram->blocks);
00140         free(gram);
00141 
00142         if (bottom_gram == NULL && unlinked == NULL) {
00143                 /* flush colormap here */
00144         }
00145 }

char* xmarkGetText  ) 
 

Definition at line 338 of file xmark.c.

References _x_gram::blocks, markgram, _xblock::strindex, string, string_Concat2, string_Copy, string_CreateFromData, _xblock::strlen, _x_gram::text, xmarkSecond(), xmarkValid, and _xblock::y.

Referenced by xcut().

00339 {
00340         int i, index, len;
00341         int last_y = -1;
00342         string temp;
00343         string text_so_far = string_Copy("");
00344         char *text = markgram->text;
00345         int startblock, endblock, startchar, endchar;
00346 
00347         if (xmarkValid()) {
00348                 if (xmarkSecond() == XMARK_END_BOUND) {
00349                         startblock = STARTBLOCK;
00350                         endblock = ENDBLOCK;
00351                         startchar = STARTCHAR;
00352                         endchar = ENDCHAR;
00353                 }
00354                 else {
00355                         startblock = ENDBLOCK;
00356                         endblock = STARTBLOCK;
00357                         startchar = ENDCHAR;
00358                         endchar = STARTCHAR;
00359                 }
00360 
00361                 for (i = startblock; i <= endblock; i++) {
00362                         if (last_y != -1 && last_y != markgram->blocks[i].y)
00363                                 text_so_far = string_Concat2(text_so_far, "\n");
00364                         index = markgram->blocks[i].strindex;
00365                         len = markgram->blocks[i].strlen;
00366                         if (startblock == endblock)
00367                                 temp = string_CreateFromData(text + index + startchar,
00368                                                        endchar - startchar);
00369                         else if (i == startblock)
00370                                 temp = string_CreateFromData(text + index + startchar, len - startchar);
00371                         else if (i == endblock)
00372                                 temp = string_CreateFromData(text + index, endchar);
00373                         else
00374                                 temp = string_CreateFromData(text + index, len);
00375                         text_so_far = string_Concat2(text_so_far, temp);
00376                         free(temp);
00377                         last_y = markgram->blocks[i].y;
00378                 }
00379         }
00380 
00381         return (text_so_far);
00382 }

void xunmark Display *  dpy,
Window  w,
x_gram gram,
XContext  desc_context
 

Definition at line 89 of file xcut.c.

References desc_context, dpy, x_gram, XMARK_REDRAW_OLD, xmarkClear(), and xmarkRedraw().

Referenced by xcut().

00094 {
00095         if (gram == NULL)
00096                 if (XFindContext(dpy, w, desc_context, (caddr_t *) & gram))
00097                         return;
00098 
00099         xmarkClear();
00100         xmarkRedraw(dpy, w, gram, XMARK_REDRAW_OLD);
00101 }


Variable Documentation

long ttl
 

Definition at line 40 of file X_gram.c.

Referenced by x_gram_init(), and xcut().



Last updated at Tue Dec 18 21:07:42 PST 2007. This site and project hosted by...SourceForge.net Logo

Source Perspective by Fisheye