From 292f4c8f9dd645563b79a44ee966245152f1b23a Mon Sep 17 00:00:00 2001 From: sabetts Date: Sat, 10 Feb 2001 22:56:13 +0000 Subject: * communications.c (send_restart, send_kill): Added * ratpoison.h: includes communications.h * main.c (send_restart, send_kill): Moved to communications.c * list.c (get_mouse_root_position): Added (add_to_window_list): Initialize new rp_window fields (save_mouse_position): Added (set_active_window): Added code to save and restore the position of the mouse * events.c (property_notify): Added code to listen for a WM_TRANSIENT_FOR property change. * data.h (struct rp_window): Added transient, transient_for, mouse_x, mouse_y. * actions.c (maximize_transient): Added (maximize): Added code to handle transient windows differently * Makefile.am (ratpoison_SOURCES): Added communications.h and communications.c --- src/ChangeLog | 37 +++++++++++++++++++++++++ src/Makefile.am | 3 ++- src/actions.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++-- src/actions.h | 21 +++++++++++++-- src/communications.c | 66 +++++++++++++++++++++++++++++++++++++++++++++ src/communications.h | 21 +++++++++++++++ src/data.h | 7 +++++ src/events.c | 8 +++++- src/input.c | 21 +++++++++++++-- src/input.h | 18 +++++++++++++ src/list.c | 45 +++++++++++++++++++++++++++++++ src/main.c | 41 ---------------------------- src/ratpoison.h | 1 + 13 files changed, 316 insertions(+), 49 deletions(-) create mode 100644 src/communications.c create mode 100644 src/communications.h diff --git a/src/ChangeLog b/src/ChangeLog index 6ea4055..69fe38b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,40 @@ +2001-02-10 shawn + + * communications.c (send_restart, send_kill): Added + + * ratpoison.h: includes communications.h + + * main.c (send_restart, send_kill): Moved to communications.c + + * list.c (get_mouse_root_position): Added + (add_to_window_list): Initialize new rp_window fields + (save_mouse_position): Added + (set_active_window): Added code to save and restore the position + of the mouse + + * events.c (property_notify): Added code to listen for a + WM_TRANSIENT_FOR property change. + + * data.h (struct rp_window): Added transient, transient_for, mouse_x, mouse_y. + + * actions.c (maximize_transient): Added + (maximize): Added code to handle transient windows differently + + * Makefile.am (ratpoison_SOURCES): Added communications.h and communications.c + +2001-01-02 shawn + + * communications.c (send_restart): moved from main.c + (send_kill): moved from main.c + + * main.c: Removed send_kill, send_restart + + * input.h: Added copyright notice. + + * input.c: Added copyright notice. + + * actions.c: Added copyright notice. + 2001-02-04 Ryan Yeske * actions.c (prev_window): do not set active window when diff --git a/src/Makefile.am b/src/Makefile.am index ea0d72d..99f2147 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,4 +2,5 @@ bin_PROGRAMS = ratpoison ratpoison_SOURCES = bar.c bar.h conf.h data.h events.c events.h \ input.c input.h list.c list.h main.c manage.c manage.h number.c \ -number.h ratpoison.h actions.h actions.c getopt.c getopt1.c getopt.h +number.h ratpoison.h actions.h actions.c getopt.c getopt1.c getopt.h \ +communications.h communications.c diff --git a/src/actions.c b/src/actions.c index 7ca7c3b..ef1fbef 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1,5 +1,20 @@ -/* actions.cpp -- all actions that can be performed with - keystrokes */ +/* + * Copyright (C) 2000 Shawn Betts + * + * 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, 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 software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA */ #include #include @@ -376,6 +391,56 @@ generate_prefix (void *data) XSync (dpy, False); } + +/* Maximize a transient window. The current window if data = 0, otherwise assume it is a + pointer to a window that should be maximized */ +static void +maximize_transient (void *data) +{ + int x, y, maxx, maxy; + rp_window *win = (rp_window *)data; + + if (!win) win = rp_current_window; + if (!win) return; + + /* Honour the window's maximum size */ + if (win->hints->flags & PMaxSize) + { + maxx = win->hints->max_width; + maxy = win->hints->max_height; + } + else + { + maxx = win->width; + maxy = win->height; + } + + /* Make sure we maximize to the nearest Resize Increment specified + by the window */ + if (win->hints->flags & PResizeInc) + { + int amount; + + amount = maxx - win->width; + amount -= amount % win->hints->width_inc; + PRINT_DEBUG ("amount x: %d\n", amount); + maxx = amount + win->width; + + amount = maxy - win->height; + amount -= amount % win->hints->height_inc; + PRINT_DEBUG ("amount y: %d\n", amount); + maxy = amount + win->height; + } + + PRINT_DEBUG ("maxsize: %d %d\n", maxx, maxy); + + x = PADDING_LEFT - win->width / 2 + (win->scr->root_attr.width - PADDING_LEFT - PADDING_RIGHT) / 2; + y = PADDING_TOP - win->height / 2 + (win->scr->root_attr.height - PADDING_TOP - PADDING_BOTTOM) / 2; + + XMoveResizeWindow (dpy, win->w, x, y, maxx, maxy); + XSync (dpy, False); +} + /* Maximize the current window if data = 0, otherwise assume it is a pointer to a window that should be maximized */ void @@ -387,6 +452,13 @@ maximize (void *data) if (!win) win = rp_current_window; if (!win) return; + /* Handle maximizing transient windows differently */ + if (win->transient) + { + maximize_transient (data); + return; + } + /* Honour the window's maximum size */ if (win->hints->flags & PMaxSize) { diff --git a/src/actions.h b/src/actions.h index b9fc2a1..ad30c2f 100644 --- a/src/actions.h +++ b/src/actions.h @@ -1,5 +1,22 @@ -/* actions.h -- prototypes of all actions that can be performed with - keystrokes */ +/* + * Copyright (C) 2000 Shawn Betts + * + * 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, 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 software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA */ + +/* Prototypes of all actions that can be performed with keystrokes. */ void switch_to(void *which); void bye(void *dummy); diff --git a/src/communications.c b/src/communications.c new file mode 100644 index 0000000..83c2cc2 --- /dev/null +++ b/src/communications.c @@ -0,0 +1,66 @@ +/* communications.c -- Send commands to a running copy of ratpoison. + * + * Copyright (C) 2000 Shawn Betts + * + * 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, 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 software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA */ + +#include +#include +#include +#include +#include + +#include "ratpoison.h" + +void +send_restart () +{ + XEvent ev; + int status; + + ev.xclient.type = ClientMessage; + ev.xclient.window = DefaultRootWindow (dpy); + ev.xclient.message_type = rp_restart; + ev.xclient.format = 32; + ev.xclient.data.l[0] = rp_restart; + ev.xclient.data.l[1] = CurrentTime; + + status = XSendEvent (dpy, DefaultRootWindow (dpy), False, SubstructureRedirectMask, &ev); + if (status == 0) + { + PRINT_ERROR ("failed to send restart event\n"); + } +} + +void +send_kill () +{ + XEvent ev; + int status; + + ev.xclient.type = ClientMessage; + ev.xclient.window = DefaultRootWindow (dpy); + ev.xclient.message_type = rp_kill; + ev.xclient.format = 32; + ev.xclient.data.l[0] = rp_kill; + ev.xclient.data.l[1] = CurrentTime; + + status = XSendEvent (dpy, DefaultRootWindow (dpy), False, SubstructureRedirectMask, &ev); + if (status == 0) + { + PRINT_ERROR ("failed to send kill event\n"); + } +} diff --git a/src/communications.h b/src/communications.h new file mode 100644 index 0000000..e6e1d06 --- /dev/null +++ b/src/communications.h @@ -0,0 +1,21 @@ +/* communications.h -- Send commands to a running copy of ratpoison. + * + * Copyright (C) 2000 Shawn Betts + * + * 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, 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 software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA */ + +void send_kill (); +void send_restart (); diff --git a/src/data.h b/src/data.h index a6ddd39..bb132f2 100644 --- a/src/data.h +++ b/src/data.h @@ -53,6 +53,13 @@ struct rp_window /* Colormap */ Colormap colormap; + /* Is this a transient window? */ + int transient; + Window transient_for; + + /* Saved mouse position */ + int mouse_x, mouse_y; + rp_window *next, *prev; }; diff --git a/src/events.c b/src/events.c index 31478ce..b95218c 100644 --- a/src/events.c +++ b/src/events.c @@ -70,12 +70,14 @@ unmap_notify (XEvent *ev) win->state = STATE_UNMAPPED; /* Update the state of the actual window */ + ignore_badwindow = 1; + XRemoveFromSaveSet (dpy, win->w); XChangeProperty(dpy, win->w, wm_state, wm_state, 32, PropModeReplace, (unsigned char *)data, 2); - ignore_badwindow = 1; XSync(dpy, False); + ignore_badwindow = 0; if (rp_current_window == win) @@ -377,6 +379,10 @@ property_notify (XEvent *ev) maximize (win); break; + case XA_WM_TRANSIENT_FOR: + PRINT_DEBUG ("Transient for\n"); + break; + default: PRINT_DEBUG ("Unhandled property notify event\n"); break; diff --git a/src/input.c b/src/input.c index e28907d..b6040fb 100644 --- a/src/input.c +++ b/src/input.c @@ -1,5 +1,22 @@ -/* for reading kdb input from the user. Currently only used to read in - the name of a window to jump to. */ +/* Read kdb input from the user. + * + * Copyright (C) 2000 Shawn Betts + * + * 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, 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 software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA */ + #include #include diff --git a/src/input.h b/src/input.h index ef2b4d3..09a7e37 100644 --- a/src/input.h +++ b/src/input.h @@ -1,3 +1,21 @@ +/* + * Copyright (C) 2000 Shawn Betts + * + * 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, 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 software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA */ + char *keysym_to_string (KeySym keysym, unsigned int modifier); void cook_keycode (KeyCode keycode, KeySym *keysym, unsigned int *mod); void get_input (screen_info *s, char *prompt, char *str, int len); diff --git a/src/list.c b/src/list.c index 72f6373..2897c41 100644 --- a/src/list.c +++ b/src/list.c @@ -27,6 +27,17 @@ rp_window *rp_window_head, *rp_window_tail; rp_window *rp_current_window; +/* Get the mouse position relative to the root of the specified window */ +static void +get_mouse_root_position (rp_window *win, int *mouse_x, int *mouse_y) +{ + Window root_win, child_win; + int win_x, win_y; + int mask; + + XQueryPointer (dpy, win->scr->root, &root_win, &child_win, &win_x, &win_y, mouse_x, mouse_y, &mask); +} + /* Allocate a new window and add it to the list of managed windows */ rp_window * add_to_window_list (screen_info *s, Window w) @@ -48,6 +59,11 @@ add_to_window_list (screen_info *s, Window w) new_window->named = 0; new_window->hints = XAllocSizeHints (); new_window->colormap = DefaultColormap (dpy, s->screen_num); + new_window->transient = XGetTransientForHint (dpy, new_window->w, &new_window->transient_for); + + get_mouse_root_position (new_window, &new_window->mouse_x, &new_window->mouse_y); + + PRINT_DEBUG ("transient %d\n", new_window->transient); if ((new_window->name = malloc (strlen ("Unnamed") + 1)) == NULL) { @@ -201,6 +217,26 @@ find_last_accessed_window () return most_recent; } +static void +save_mouse_position (rp_window *win) +{ + Window root_win, child_win; + int win_x, win_y; + int mask; + + /* In the case the XQueryPointer raises a BadWindow error, the + window is not mapped or has been destroyed so it doesn't matter + what we store in mouse_x and mouse_y since they will never be + used again. */ + + ignore_badwindow = 1; + + XQueryPointer (dpy, win->w, &root_win, &child_win, + &win_x, &win_y, &win->mouse_x, &win->mouse_y, &mask); + + ignore_badwindow = 0; +} + void set_active_window (rp_window *rp_w) { @@ -215,6 +251,14 @@ set_active_window (rp_window *rp_w) if (rp_w->scr->bar_is_raised) update_window_names (rp_w->scr); + if (rp_current_window != NULL) + { + save_mouse_position (rp_current_window); + } + + XWarpPointer (dpy, None, rp_w->w, 0, 0, 0, 0, rp_w->mouse_x, rp_w->mouse_y); + XSync (dpy, False); + XSetInputFocus (dpy, rp_w->w, RevertToPointerRoot, CurrentTime); XRaiseWindow (dpy, rp_w->w); @@ -227,6 +271,7 @@ set_active_window (rp_window *rp_w) XInstallColormap (dpy, rp_w->colormap); rp_current_window = rp_w; + /* Make sure the program bar is always on the top */ update_window_names (rp_w->scr); diff --git a/src/main.c b/src/main.c index 4127abd..7a00205 100644 --- a/src/main.c +++ b/src/main.c @@ -72,47 +72,6 @@ sighandler () exit (EXIT_FAILURE); } -void -send_restart () -{ - XEvent ev; - int status; - - ev.xclient.type = ClientMessage; - ev.xclient.window = DefaultRootWindow (dpy); - ev.xclient.message_type = rp_restart; - ev.xclient.format = 32; - ev.xclient.data.l[0] = rp_restart; - ev.xclient.data.l[1] = CurrentTime; - - status = XSendEvent (dpy, DefaultRootWindow (dpy), False, SubstructureRedirectMask, &ev); - if (status == 0) - { - PRINT_ERROR ("failed to send restart event\n"); - } -} - -void -send_kill () -{ - XEvent ev; - int status; - - ev.xclient.type = ClientMessage; - ev.xclient.window = DefaultRootWindow (dpy); - ev.xclient.message_type = rp_kill; - ev.xclient.format = 32; - ev.xclient.data.l[0] = rp_kill; - ev.xclient.data.l[1] = CurrentTime; - - status = XSendEvent (dpy, DefaultRootWindow (dpy), False, SubstructureRedirectMask, &ev); - if (status == 0) - { - PRINT_ERROR ("failed to send kill event\n"); - } -} - - void hup_handler () { diff --git a/src/ratpoison.h b/src/ratpoison.h index e5d0a35..ac6b5a1 100644 --- a/src/ratpoison.h +++ b/src/ratpoison.h @@ -49,6 +49,7 @@ #include "events.h" #include "number.h" #include "input.h" +#include "communications.h" void clean_up (); screen_info *find_screen (Window w); -- cgit v1.2.3