Skip to content

Commit

Permalink
Store a copy of the display pointer in each client at initialization.…
Browse files Browse the repository at this point in the history
… Use it

throughout to shorten calls.
  • Loading branch information
alisabedard committed Jun 7, 2017
1 parent dde77d4 commit 09d5949
Show file tree
Hide file tree
Showing 35 changed files with 265 additions and 264 deletions.
3 changes: 2 additions & 1 deletion JBWMClient.h
Expand Up @@ -4,13 +4,14 @@
// See README for license and other details.
#ifndef JBWM_CLIENT_STRUCT_H
#define JBWM_CLIENT_STRUCT_H
#include <X11/X.h>
#include <X11/Xlib.h>
#include "JBWMClientOptions.h"
#include "JBWMClientTitlebar.h"
#include "JBWMRectangle.h"
struct JBWMScreen;
struct JBWMClient {
struct JBWMClient * next;
Display * display;
#ifdef JBWM_USE_TITLE_BAR
struct JBWMClientTitlebar tb;
#endif//JBWM_USE_TITLE_BAR
Expand Down
14 changes: 7 additions & 7 deletions button_event.c
Expand Up @@ -17,17 +17,17 @@ static void handle_title_bar_button(XButtonEvent * e,
(int)e->window, (int)c->tb.win, (int)e->subwindow);
struct JBWMClientOptions * o = &c->opt;
if (!e->subwindow)
jbwm_drag(e->display, c, false);
jbwm_drag(c, false);
else if (e->subwindow == c->tb.close && !o->no_close)
jbwm_send_wm_delete(e->display, c);
jbwm_send_wm_delete(c);
else if (e->subwindow == c->tb.resize && !o->no_resize)
jbwm_drag(e->display, c, !c->opt.no_resize);
jbwm_drag(c, !c->opt.no_resize);
else if (e->subwindow == c->tb.shade && !c->opt.no_min)
jbwm_toggle_shade(e->display, c);
jbwm_toggle_shade(c);
else if (e->subwindow == c->tb.stick)
jbwm_toggle_sticky(e->display, c);
jbwm_toggle_sticky(c);
else
jbwm_drag(e->display, c, false);
jbwm_drag(c, false);
}
#else//!JBWM_USE_TITLE_BAR
#define handle_title_bar_button(e, c) jbwm_drag(d, c, false)
Expand Down Expand Up @@ -58,7 +58,7 @@ void jbwm_handle_button_event(XButtonEvent * e,
if (fs)
XLowerWindow(d, c->parent);
else
jbwm_drag(d, c, !c->opt.shaded);
jbwm_drag(c, !c->opt.shaded);
break;
}
}
39 changes: 20 additions & 19 deletions client.c
Expand Up @@ -48,15 +48,15 @@ void jbwm_relink_client_list(struct JBWMClient * restrict c)
}
relink_r(c, head);
}
void jbwm_set_client_vdesk(Display * d, struct JBWMClient * restrict c,
void jbwm_set_client_vdesk(struct JBWMClient * restrict c,
const uint8_t desktop)
{
const uint8_t p = c->vdesk; // save previous
c->vdesk = desktop;
// use jbwm_set_vdesk to validate desktop:
struct JBWMScreen * s = &jbwm_get_screens()[c->screen];
c->vdesk = jbwm_set_vdesk(d, s, desktop);
jbwm_set_vdesk(d, s, p);
c->vdesk = jbwm_set_vdesk(c->display, s, desktop);
jbwm_set_vdesk(c->display, s, p);
}
static inline bool matches(struct JBWMClient * i,
const Window w)
Expand All @@ -79,14 +79,14 @@ struct JBWMClient * jbwm_get_client(const Window w)
{
return search(head, w);
}
void jbwm_toggle_sticky(Display * d, struct JBWMClient * restrict c)
void jbwm_toggle_sticky(struct JBWMClient * restrict c)
{
c->opt.sticky ^= true; // toggle
jbwm_select_client(d, c);
jbwm_update_title_bar(d, c);
jbwm_select_client(c);
jbwm_update_title_bar(c);
#ifdef JBWM_USE_EWMH
(c->opt.sticky ? jbwm_ewmh_add_state : jbwm_ewmh_remove_state)
(d, c->window,jbwm_ewmh_get_atom(
(c->display, c->window,jbwm_ewmh_get_atom(
JBWM_EWMH_WM_STATE_STICKY));
#endif//JBWM_USE_EWMH
}
Expand All @@ -102,37 +102,38 @@ static void delete_ewmh_properties(Display * d,
#define delete_ewmh_properties(d, w)
#endif//JBWM_USE_EWMH
static void
free_window(Display * d, struct JBWMClient * restrict c)
free_window(struct JBWMClient * restrict c)
{
const Window w = c->window;
Display * d = c->display;
delete_ewmh_properties(d, w);
{ // * p scope
struct JBWMRectangle * restrict p = &c->size;
XReparentWindow(d, w, jbwm_get_root(d, c), p->x, p->y);
XReparentWindow(d, w, jbwm_get_root(c), p->x, p->y);
}
XRemoveFromSaveSet(d, w);
}
// Free client and destroy its windows and properties.
void jbwm_client_free(Display * d, struct JBWMClient * restrict c)
void jbwm_client_free(struct JBWMClient * restrict c)
{
free_window(d, c);
free_window(c);
if(c->parent)
XDestroyWindow(d, c->parent);
XDestroyWindow(c->display, c->parent);
jbwm_relink_client_list(c);
free(c);
}
static void showing(Display * d, struct JBWMClient * restrict c,
static void showing(struct JBWMClient * restrict c,
int (* mapping)(Display *, Window),
const int8_t wm_state)
{
mapping(d, c->parent);
jbwm_set_wm_state(d, c, wm_state);
mapping(c->display, c->parent);
jbwm_set_wm_state(c, wm_state);
}
void jbwm_hide_client(Display * d, struct JBWMClient * restrict c)
void jbwm_hide_client(struct JBWMClient * restrict c)
{
showing(d, c, XUnmapWindow, IconicState);
showing(c, XUnmapWindow, IconicState);
}
void jbwm_restore_client(Display * d, struct JBWMClient * restrict c)
void jbwm_restore_client(struct JBWMClient * restrict c)
{
showing(d, c, XMapWindow, NormalState);
showing(c, XMapWindow, NormalState);
}
11 changes: 5 additions & 6 deletions client.h
Expand Up @@ -8,29 +8,28 @@
#include <X11/Xlib.h>
struct JBWMClient;
// Free client and destroy its windows and properties.
void jbwm_client_free(Display * d,
struct JBWMClient * restrict c) __attribute__((nonnull));
void jbwm_client_free(struct JBWMClient * c);
// Search for the JBWMClient matching the specified window
struct JBWMClient * jbwm_get_client(Window w)
__attribute__((pure));
// Get the client with input focus.
struct JBWMClient * jbwm_get_current_client(void);
// Get the head of the JBWMClient linked list
struct JBWMClient * jbwm_get_head_client(void);
void jbwm_hide_client(Display * d, struct JBWMClient * restrict c)
void jbwm_hide_client(struct JBWMClient * restrict c)
__attribute__((nonnull));
/* Set c as the new head client, linking its next element
to the previous head */
void jbwm_prepend_client(struct JBWMClient * restrict c);
// Relink c's linked list to exclude c
void jbwm_relink_client_list(struct JBWMClient * restrict c);
// Move the client to the specified virtual desktop
void jbwm_set_client_vdesk(Display * d, struct JBWMClient * restrict c,
void jbwm_set_client_vdesk(struct JBWMClient * restrict c,
const uint8_t desktop) __attribute((nonnull));
// Assign c as the current client
void jbwm_set_current_client(struct JBWMClient * restrict c);
void jbwm_toggle_sticky(Display * d, struct JBWMClient * restrict c)
void jbwm_toggle_sticky(struct JBWMClient * restrict c)
__attribute__((nonnull));
void jbwm_restore_client(Display * d, struct JBWMClient * restrict c)
void jbwm_restore_client(struct JBWMClient * restrict c)
__attribute__((nonnull));
#endif//!JBWM_CLIENT_H
8 changes: 4 additions & 4 deletions display.c
Expand Up @@ -8,14 +8,14 @@
#include "config.h"
#include "log.h"
#include "util.h"
static void cleanup(Display * display, const Window w)
static void cleanup(const Window w)
{
struct JBWMClient * restrict c = jbwm_get_client(w);
if (c) // match found
jbwm_client_free(display, c);
jbwm_client_free(c);
}
__attribute__((pure))
static int handle_xerror(Display * d,
static int handle_xerror(Display * d __attribute__((unused)),
XErrorEvent * restrict e)
{
switch (e->error_code) {
Expand All @@ -24,7 +24,7 @@ static int handle_xerror(Display * d,
jbwm_error("Cannot access the root window");
break;
case BadWindow:
cleanup(d, e->resourceid);
cleanup(e->resourceid);
return 0;
case BadAtom:
return 0;
Expand Down
14 changes: 7 additions & 7 deletions drag.c
Expand Up @@ -37,14 +37,14 @@ static int get_diff(const uint8_t i, const int16_t * restrict original,
{
return original[i] - start[i] + p[i];
}
static void set_position(Display * d, struct JBWMClient * restrict c,
static void set_position(struct JBWMClient * restrict c,
const int16_t * restrict original,
const int16_t * restrict start,
const int16_t * restrict p)
{
c->size.x = get_diff(0, original, start, p);
c->size.y = get_diff(1, original, start, p);
jbwm_snap_client(d, c);
jbwm_snap_client(c);
}
__attribute__((nonnull))
static void query_pointer(Display * dpy, Window w,
Expand Down Expand Up @@ -93,18 +93,18 @@ static void drag_event_loop(Display * d,
if (resize)
set_size(c, p);
else
set_position(d, c, original, start, p);
set_position(c, original, start, p);
}
if (b)
draw_outline(d, root, gc, c);
else
jbwm_move_resize(d, c);
jbwm_move_resize(c);
}
}
/* Drag the specified client. Resize the client if resize is true. */
void jbwm_drag(Display * d, struct JBWMClient * restrict c,
const bool resize)
void jbwm_drag(struct JBWMClient * restrict c, const bool resize)
{
Display * d = c->display;
XRaiseWindow(d, c->parent);
if (resize && (c->opt.no_resize || c->opt.shaded))
return;
Expand All @@ -122,6 +122,6 @@ void jbwm_drag(Display * d, struct JBWMClient * restrict c,
draw_outline(d, r, gc, c);
}
XUngrabPointer(d, CurrentTime);
jbwm_move_resize(d, c);
jbwm_move_resize(c);
}

4 changes: 2 additions & 2 deletions drag.h
Expand Up @@ -5,8 +5,8 @@
#include <stdbool.h>
struct JBWMClient;
/* Drag the specified client. Resize the client if resize is true. */
void jbwm_drag(Display * d, struct JBWMClient * restrict c,
const bool resize) __attribute__((nonnull));
void jbwm_drag(struct JBWMClient * restrict c, const bool resize)
__attribute__((nonnull));
/* Warp the pointer to the specified position. */
inline void jbwm_warp(Display * dpy, const Window w, const short x,
const short y)
Expand Down
14 changes: 7 additions & 7 deletions events.c
Expand Up @@ -31,7 +31,7 @@ static void cleanup(Display * d, struct JBWMClient * i)
return;
struct JBWMClient * next = i->next; // save
if (i->opt.remove)
jbwm_client_free(d, i);
jbwm_client_free(i);
cleanup(d, next);
}
static void handle_property_change(XPropertyEvent * e,
Expand All @@ -40,12 +40,12 @@ static void handle_property_change(XPropertyEvent * e,
if (e->state != PropertyNewValue)
return;
if (e->atom == XA_WM_NAME)
jbwm_update_title_bar(e->display, c);
jbwm_update_title_bar(c);
else {
Display * d = e->display;
jbwm_print_atom(d, e->atom, __FILE__, __LINE__);
if (e->atom == jbwm_get_wm_state(d))
jbwm_move_resize(d, c);
jbwm_move_resize(c);
}
}
static void handle_configure_request(XConfigureRequestEvent * e)
Expand Down Expand Up @@ -99,13 +99,13 @@ void jbwm_events_loop(Display * d)
break;
case ConfigureNotify:
if (c && !ev.xconfigure.override_redirect)
jbwm_move_resize(d, c);
jbwm_move_resize(c);
break;
case ConfigureRequest:
handle_configure_request(&ev.xconfigurerequest);
XSync(d, false);
if (c)
jbwm_move_resize(d, c);
jbwm_move_resize(c);
break;
case KeyPress:
JBWM_LOG("KeyPress");
Expand All @@ -118,12 +118,12 @@ void jbwm_events_loop(Display * d)
break;
case EnterNotify:
if (c && ev.xcrossing.window == c->parent)
jbwm_select_client(d, c);
jbwm_select_client(c);
break;
#ifdef JBWM_USE_TITLE_BAR
case Expose:
if (c && !ev.xexpose.count)
jbwm_update_title_bar(d, c);
jbwm_update_title_bar(c);
break;
#endif//JBWM_USE_TITLE_BAR
#ifdef JBWM_USE_EWMH
Expand Down
5 changes: 3 additions & 2 deletions ewmh.c
Expand Up @@ -175,7 +175,7 @@ void jbwm_ewmh_init_screen(Display * d, struct JBWMScreen * s)
s->supporting = init_supporting(d, r);
}
// Required by wm-spec:
void jbwm_set_frame_extents(Display * d, struct JBWMClient * restrict c)
void jbwm_set_frame_extents(struct JBWMClient * restrict c)
{
JBWM_LOG("jbwm_set_frame_extents()");
// Fields: left, right, top, bottom
Expand All @@ -184,5 +184,6 @@ void jbwm_set_frame_extents(Display * d, struct JBWMClient * restrict c)
f[0] = f[1] = f[2] = f[3] = b;
if (!c->opt.no_title_bar)
f[2] += jbwm_get_font_height();
wprop(d, c->parent, JBWM_EWMH_FRAME_EXTENTS, XA_CARDINAL, f, 4);
wprop(c->display, c->parent, JBWM_EWMH_FRAME_EXTENTS,
XA_CARDINAL, f, 4);
}
2 changes: 1 addition & 1 deletion ewmh.h
Expand Up @@ -15,7 +15,7 @@ void jbwm_ewmh_set_allowed_actions(Display * d,
const Window w) __attribute__((nonnull));
void jbwm_ewmh_init_screen(Display * d, struct JBWMScreen * s)
__attribute__((nonnull));
void jbwm_set_frame_extents(Display * d, struct JBWMClient * restrict c);
void jbwm_set_frame_extents(struct JBWMClient * restrict c);
enum JBWMAtomIndex {
JBWM_EWMH_SUPPORTED,
JBWM_EWMH_CURRENT_DESKTOP,
Expand Down
8 changes: 4 additions & 4 deletions ewmh_client.c
Expand Up @@ -41,17 +41,17 @@ static bool client_specific_message(XClientMessageEvent * e,
Display * d = e->display;
jbwm_print_atom(d, t, __FILE__, __LINE__);
if (t == jbwm_ewmh_get_atom(JBWM_EWMH_WM_DESKTOP))
jbwm_set_client_vdesk(d, c, e->data.l[0]);
jbwm_set_client_vdesk(c, e->data.l[0]);
// If user moves window (client-side title bars):
else if (t == jbwm_ewmh_get_atom(JBWM_EWMH_WM_MOVERESIZE)) {
XRaiseWindow(d, c->parent);
jbwm_drag(d, c, false);
jbwm_drag(c, false);
} else if (t == jbwm_ewmh_get_atom(JBWM_EWMH_WM_STATE))
jbwm_ewmh_handle_wm_state_changes(e, c);
else if (t == jbwm_ewmh_get_atom(JBWM_EWMH_ACTIVE_WINDOW))
jbwm_select_client(d, c);
jbwm_select_client(c);
else if (t == jbwm_ewmh_get_atom(JBWM_EWMH_CLOSE_WINDOW))
jbwm_send_wm_delete(d, c);
jbwm_send_wm_delete(c);
else
return false;
return true;
Expand Down

0 comments on commit 09d5949

Please sign in to comment.