CTWM
Loading...
Searching...
No Matches
/usr/src/RPM/BUILD/ctwm-4.1.0/functions_warp.c
Go to the documentation of this file.
1/*
2 * Functions related to the warp ring
3 *
4 * There are functions that are _named_ like warp-ring funcs, but aren't
5 * really, and so aren't here. Some examples are f.warphere which is
6 * workspaces-related, and f.warptoscreen which is screen-related.
7 *
8 * There are also funcs that aren't really ring related, but I've put
9 * here because they're still warping to window related, like f.warpto /
10 * f.warptoiconmgr.
11 */
12
13#include "ctwm.h"
14
15#include <string.h>
16
17#include "functions_internal.h"
18#include "iconmgr.h"
19#include "list.h"
20#include "otp.h"
21#include "screen.h"
22#include "win_iconify.h"
23#include "win_ring.h"
24#include "win_utils.h"
25
26
27static void WarpAlongRing(XButtonEvent *ev, bool forward);
28
29
31{
33 int len;
34
35 len = strlen(action);
36
37#ifdef WARPTO_FROM_ICONMGR
38 /* XXX should be iconmgrp? */
39 if(len == 0 && tmp_win && tmp_win->iconmgr) {
40 printf("curren iconmgr entry: %s", tmp_win->iconmgr->Current);
41 }
42#endif /* #ifdef WARPTO_FROM_ICONMGR */
43 for(tw = Scr->FirstWindow; tw != NULL; tw = tw->next) {
44 if(!strncmp(action, tw->name, len)) {
45 break;
46 }
47 if(match(action, tw->name)) {
48 break;
49 }
50 }
51 if(!tw) {
52 for(tw = Scr->FirstWindow; tw != NULL; tw = tw->next) {
53 if(!strncmp(action, tw->class.res_name, len)) {
54 break;
55 }
56 if(match(action, tw->class.res_name)) {
57 break;
58 }
59 }
60 if(!tw) {
61 for(tw = Scr->FirstWindow; tw != NULL; tw = tw->next) {
62 if(!strncmp(action, tw->class.res_class, len)) {
63 break;
64 }
65 if(match(action, tw->class.res_class)) {
66 break;
67 }
68 }
69 }
70 }
71
72 if(tw) {
73 if(Scr->WarpUnmapped || tw->mapped) {
74 if(!tw->mapped) {
76 }
77 WarpToWindow(tw, Scr->RaiseOnWarp);
78 }
79 }
80 else {
81 XBell(dpy, 0);
82 }
83}
84
85
87{
89 int len;
91
92 len = strlen(action);
93 if(len == 0) {
94 if(tmp_win && tmp_win->iconmanagerlist) {
95 raisewin = tmp_win->iconmanagerlist->iconmgr->twm_win;
96 iconwin = tmp_win->iconmanagerlist->icon;
97 }
98 else if(Scr->iconmgr->active) {
99 raisewin = Scr->iconmgr->twm_win;
100 iconwin = Scr->iconmgr->active->w;
101 }
102 }
103 else {
104 for(tw = Scr->FirstWindow; tw != NULL; tw = tw->next) {
105 if(strncmp(action, tw->icon_name, len) == 0) {
106 if(tw->iconmanagerlist &&
107 tw->iconmanagerlist->iconmgr->twm_win->mapped) {
108 raisewin = tw->iconmanagerlist->iconmgr->twm_win;
109 break;
110 }
111 }
112 }
113 }
114
115 if(raisewin) {
117 XWarpPointer(dpy, None, iconwin, 0, 0, 0, 0, 5, 5);
118 }
119 else {
120 XBell(dpy, 0);
121 }
122}
123
124/* Taken from vtwm version 5.3 */
126{
128 /* It's in the ring, let's take it out. */
130 }
131 else {
132 /* Not in the ring, so put it in. */
134 }
135 /*tmp_win->ring.cursor_valid = false;*/
136}
137
138
140{
141 switch(((char *)action)[0]) {
142 case 'n':
143 WarpAlongRing(&eventp->xbutton, true);
144 break;
145 case 'p':
146 WarpAlongRing(&eventp->xbutton, false);
147 break;
148 default:
149 XBell(dpy, 0);
150 break;
151 }
152}
153
154
155/*
156 * Synthetic function: this is used internally as the action in some
157 * magic menus like the TwmWindows et al.
158 */
160{
161 tmp_win = (TwmWindow *)action;
162
163 if(! tmp_win) {
164 return;
165 }
166 if(Scr->WarpUnmapped || tmp_win->mapped) {
167 if(!tmp_win->mapped) {
169 }
170 WarpToWindow(tmp_win, Scr->RaiseOnWarp);
171 }
172}
173
174
175/*
176 * Backend util for f.warpring
177 */
178static void
180{
181 TwmWindow *r, *head;
182
183 if(Scr->RingLeader) {
184 head = Scr->RingLeader;
185 }
186 else if(!(head = Scr->Ring)) {
187 return;
188 }
189
190 if(forward) {
191 for(r = head->ring.next; r != head; r = r->ring.next) {
192 if(r->mapped && (Scr->WarpRingAnyWhere || visible(r))) {
193 break;
194 }
195 }
196 }
197 else {
198 for(r = head->ring.prev; r != head; r = r->ring.prev) {
199 if(r->mapped && (Scr->WarpRingAnyWhere || visible(r))) {
200 break;
201 }
202 }
203 }
204
205 /*
206 * Note: (Scr->Focus == NULL) is necessary when we move to (or
207 * are in) a workspace that has a single window, and we're not
208 * on that window (but the window is head), and we want f.warpring
209 * to warp to it.
210 * Generalised that is also true if we are on a window but it is
211 * not on the ring.
212 * TODO: on an empty screen, it still moves the mouse cursor...
213 */
214
215 if(r != head
216 || Scr->Focus == NULL
217 || !WindowIsOnRing(Scr->Focus)) {
218 TwmWindow *p = Scr->RingLeader, *t;
219
220 Scr->RingLeader = r;
221 WarpToWindow(r, true);
222
223 if(p && p->mapped &&
224 (t = GetTwmWindow(ev->window)) &&
225 p == t) {
226 p->ring.cursor_valid = true;
227 p->ring.curs_x = ev->x_root - t->frame_x;
228 p->ring.curs_y = ev->y_root - t->frame_y;
229#ifdef DEBUG
230 /* XXX This is the Tmp_win [now] internal to the event code? */
232 "WarpAlongRing: cursor_valid := true; x := %d (%d-%d), y := %d (%d-%d)\n",
233 Tmp_win->ring.curs_x, ev->x_root, t->frame_x, Tmp_win->ring.curs_y, ev->y_root,
234 t->frame_y);
235#endif
236 /*
237 * The check if the cursor position is inside the window is now
238 * done in WarpToWindow().
239 */
240 }
241 }
242}
static int PlaceX
Definition add_window.c:82
Display * dpy
Definition ctwm_main.c:84
#define Scr
TwmWindow * Tmp_win
Definition event_core.c:91
#define DFHANDLER(func)
static void WarpAlongRing(XButtonEvent *ev, bool forward)
int match(const char *p, const char *t)
Definition list.c:433
void OtpRaise(TwmWindow *twm_win, WinType wintype)
Definition otp.c:763
@ WinWin
Definition otp.h:14
static int len
Definition parse.c:75
struct TwmWindow * prev
Previous window in the ring.
int curs_x
Stored cursor position in the window.
int curs_y
Stored cursor position in the window.
struct TwmWindow * next
Next window in the ring.
Info and control for every X Window we take over.
struct TwmWindow::_ring ring
Window ring connectivity. "
void DeIconify(TwmWindow *tmp_win)
void UnlinkWindowFromRing(TwmWindow *win)
Definition win_ring.c:26
void AddWindowToRing(TwmWindow *win)
Definition win_ring.c:77
#define WindowIsOnRing(win)
Definition win_ring.h:10
bool visible(const TwmWindow *tmp_win)
Definition win_utils.c:341
TwmWindow * GetTwmWindow(Window w)
Definition win_utils.c:190
void WarpToWindow(TwmWindow *t, bool must_raise)
Definition win_utils.c:883