Cfactor: Add cfactor.c and move all client_factor function of client.c
This commit is contained in:
parent
813d88ff7a
commit
4a804a740b
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,7 +3,6 @@
|
||||
wmfs
|
||||
#*
|
||||
\#*
|
||||
Makefile
|
||||
wmfs.1.gz
|
||||
tags
|
||||
*.patch
|
||||
|
||||
78
Makefile
Normal file
78
Makefile
Normal file
@ -0,0 +1,78 @@
|
||||
#
|
||||
# Makefile to use with BSDBuild
|
||||
#
|
||||
# Copyright (c) 2011, David "markand" Demelier <markand@malikania.fr>
|
||||
#
|
||||
# Permission to use, copy, modify, and/or distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
|
||||
TOP= .
|
||||
PROG= wmfs
|
||||
SRCS= src/barwin.c \
|
||||
src/cfactor.c \
|
||||
src/client.c \
|
||||
src/config.c \
|
||||
src/draw.c \
|
||||
src/event.c \
|
||||
src/ewmh.c \
|
||||
src/frame.c \
|
||||
src/getinfo.c \
|
||||
src/infobar.c \
|
||||
src/init.c \
|
||||
src/launcher.c \
|
||||
src/layout.c \
|
||||
src/menu.c \
|
||||
src/mouse.c \
|
||||
src/parse_api.c \
|
||||
src/parse.c \
|
||||
src/screen.c \
|
||||
src/status.c \
|
||||
src/systray.c \
|
||||
src/tag.c \
|
||||
src/util.c \
|
||||
src/viwmfs.c \
|
||||
src/color.c \
|
||||
src/wmfs.c
|
||||
|
||||
|
||||
include ${TOP}/Makefile.config
|
||||
include ${TOP}/mk/build.prog.mk
|
||||
|
||||
CFLAGS+= -Wall
|
||||
|
||||
# Include dirs
|
||||
CFLAGS+= ${X11_CFLAGS}
|
||||
CFLAGS+= ${XFT_CFLAGS}
|
||||
CFLAGS+= ${FREETYPE_CFLAGS}
|
||||
CFLAGS+= ${PTHREADS_CFLAGS}
|
||||
CFLAGS+= ${XINERAMA_CFLAGS}
|
||||
CFLAGS+= ${XRANDR_CFLAGS}
|
||||
CFLAGS+= ${IMLIB2_CFLAGS}
|
||||
|
||||
# XDG Dir and WMFS version
|
||||
CFLAGS+= -DXDG_CONFIG_DIR=\"${XDG_CONFIG_DIR}\"
|
||||
CFLAGS+= -DWMFS_VERSION=\"201104\"
|
||||
|
||||
# Libs dirs
|
||||
LIBS+= ${X11_LIBS}
|
||||
LIBS+= ${XFT_LIBS}
|
||||
LIBS+= ${FREETYPE_LIBS}
|
||||
LIBS+= ${PTHREADS_LIBS}
|
||||
LIBS+= ${XINERAMA_LIBS}
|
||||
LIBS+= ${XRANDR_LIBS}
|
||||
LIBS+= ${IMLIB2_LIBS}
|
||||
|
||||
# Install man and wmfsrc
|
||||
install:
|
||||
${INSTALL_DATA} wmfs.1 ${MANDIR}/man1
|
||||
${INSTALL_DATA} wmfsrc ${XDG_CONFIG_DIR}/wmfs/
|
||||
193
src/cfactor.c
Normal file
193
src/cfactor.c
Normal file
@ -0,0 +1,193 @@
|
||||
/*
|
||||
* cfactor.c
|
||||
* Copyright © 2011 Martin Duquesnoy <xorg62@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of the nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "wmfs.h"
|
||||
|
||||
/** Clean client tile factors
|
||||
*\param c Client pointer
|
||||
*/
|
||||
void
|
||||
cfactor_clean(Client *c)
|
||||
{
|
||||
CHECK(c);
|
||||
|
||||
if(!tags[c->screen][c->tag].cleanfact)
|
||||
return;
|
||||
|
||||
c->tilefact[Right] = c->tilefact[Left] = 0;
|
||||
c->tilefact[Top] = c->tilefact[Bottom] = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** Return new geo of client with factors applied
|
||||
*\param c Client pointer
|
||||
*\return geo
|
||||
*/
|
||||
XRectangle
|
||||
cfactor_geo(XRectangle geo, int fact[4])
|
||||
{
|
||||
XRectangle cgeo = { 0, 0, 0, 0 };
|
||||
|
||||
cgeo = geo;
|
||||
|
||||
/* Right factor */
|
||||
cgeo.width += fact[Right];
|
||||
|
||||
/* Left factor */
|
||||
cgeo.x -= fact[Left];
|
||||
cgeo.width += fact[Left];
|
||||
|
||||
/* Top factor */
|
||||
cgeo.y -= fact[Top];
|
||||
cgeo.height += fact[Top];
|
||||
|
||||
/* Bottom factor */
|
||||
cgeo.height += fact[Bottom];
|
||||
|
||||
return cgeo;
|
||||
}
|
||||
|
||||
|
||||
/** Manual resizing of tiled clients
|
||||
* \param c Client pointer
|
||||
* \param p Direction of resizing
|
||||
* \param fac Factor of resizing
|
||||
*/
|
||||
static void
|
||||
cfactor_set(Client *c, Position p, int fac)
|
||||
{
|
||||
Client *gc = NULL;
|
||||
int x, y;
|
||||
XRectangle cgeo, scgeo;
|
||||
Position reversepos[4] = { Left, Right, Bottom, Top };
|
||||
int cfact[4] = { 0 }, scfact[4] = { 0 };
|
||||
char scanfac[4][3] =
|
||||
{
|
||||
{ 1, 0 }, { -1, 0 }, /* Right, Left */
|
||||
{ 0, -1 }, { 0, 1 } /* Top, Bottom */
|
||||
};
|
||||
|
||||
if(!c || p > Bottom)
|
||||
return;
|
||||
|
||||
/* Start place of pointer for faster scanning */
|
||||
x = c->geo.x + ((p == Right) ? c->geo.width : 0);
|
||||
y = c->geo.y + ((p == Bottom) ? c->geo.height : 0);
|
||||
y += ((p < Top) ? c->geo.height / 2 : 0);
|
||||
x += ((p > Left) ? c->geo.width / 2 : 0);
|
||||
|
||||
/* Scan in right direction to next(p) physical client */
|
||||
for(; (gc = client_gb_pos(c, x, y)) == c; x += scanfac[p][0], y += scanfac[p][1]);
|
||||
|
||||
if(!gc || c->screen != gc->screen)
|
||||
return;
|
||||
|
||||
cfact[p] += fac;
|
||||
scfact[reversepos[p]] -= fac;
|
||||
|
||||
cgeo = cfactor_geo(c->geo, cfact);
|
||||
scgeo = cfactor_geo(gc->geo, scfact);
|
||||
|
||||
/* Too big */
|
||||
if(scgeo.width > (1 << 15) || scgeo.height > (1 << 15)
|
||||
|| cgeo.width > (1 << 15) || cgeo.height > (1 << 15))
|
||||
return;
|
||||
|
||||
/* Too small */
|
||||
if(scgeo.width < 1 || scgeo.height < 1
|
||||
|| cgeo.width < 1 || cgeo.height < 1)
|
||||
return;
|
||||
|
||||
/* Check if move/resize is needed for same col/row clients */
|
||||
/*for(sc = tiled_client(c->screen, clients); sc; tiled_client(c->screen, c->next))
|
||||
if(sc->geo.*/
|
||||
|
||||
c->tilefact[p] += fac;
|
||||
gc->tilefact[reversepos[p]] -= fac;
|
||||
|
||||
/* Magic moment */
|
||||
client_moveresize(c, cgeo, tags[c->screen][c->tag].resizehint);
|
||||
client_moveresize(gc, scgeo, tags[gc->screen][gc->tag].resizehint);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
uicb_client_resize_right(uicb_t cmd)
|
||||
{
|
||||
int n = atoi(cmd);
|
||||
|
||||
CHECK(sel);
|
||||
|
||||
cfactor_set(sel, Right, n);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
uicb_client_resize_left(uicb_t cmd)
|
||||
{
|
||||
int n = atoi(cmd);
|
||||
|
||||
CHECK(sel);
|
||||
|
||||
cfactor_set(sel, Left, n);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
uicb_client_resize_top(uicb_t cmd)
|
||||
{
|
||||
int n = atoi(cmd);
|
||||
|
||||
CHECK(sel);
|
||||
|
||||
cfactor_set(sel, Top, n);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
uicb_client_resize_bottom(uicb_t cmd)
|
||||
{
|
||||
int n = atoi(cmd);
|
||||
|
||||
CHECK(sel);
|
||||
|
||||
cfactor_set(sel, Bottom, n);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
165
src/client.c
165
src/client.c
@ -888,7 +888,7 @@ client_manage(Window w, XWindowAttributes *wa, Bool ar)
|
||||
c->free_geo = c->pgeo = c->geo;
|
||||
c->tag = seltag[c->screen];
|
||||
c->focusontag = -1;
|
||||
client_clean_tile_fact(c);
|
||||
cfactor_clean(c);
|
||||
|
||||
at.event_mask = PropertyChangeMask;
|
||||
|
||||
@ -1048,7 +1048,7 @@ client_moveresize(Client *c, XRectangle geo, Bool r)
|
||||
c->tag = seltag[c->screen];
|
||||
|
||||
if(c->flags & TileFlag)
|
||||
c->geo = client_get_geo_factor(c->pgeo, c->tilefact);
|
||||
c->geo = cfactor_geo(c->pgeo, c->tilefact);
|
||||
|
||||
frame_moveresize(c, c->geo);
|
||||
|
||||
@ -1353,10 +1353,6 @@ client_unmanage(Client *c)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*XFree(c->title);*/
|
||||
|
||||
client_focus_next(c);
|
||||
|
||||
free(c);
|
||||
@ -1689,160 +1685,3 @@ uicb_client_set_master(uicb_t cmd)
|
||||
return;
|
||||
}
|
||||
|
||||
/** Clean client tile factors
|
||||
*\param c Client pointer
|
||||
*/
|
||||
void
|
||||
client_clean_tile_fact(Client *c)
|
||||
{
|
||||
CHECK(c);
|
||||
|
||||
if(!tags[c->screen][c->tag].cleanfact)
|
||||
return;
|
||||
|
||||
c->tilefact[Right] = c->tilefact[Left] = 0;
|
||||
c->tilefact[Top] = c->tilefact[Bottom] = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** Return new geo of client with factors applied
|
||||
*\param c Client pointer
|
||||
*\return geo
|
||||
*/
|
||||
XRectangle
|
||||
client_get_geo_factor(XRectangle geo, int fact[4])
|
||||
{
|
||||
XRectangle cgeo = { 0, 0, 0, 0 };
|
||||
|
||||
cgeo = geo;
|
||||
|
||||
/* Right factor */
|
||||
cgeo.width += fact[Right];
|
||||
|
||||
/* Left factor */
|
||||
cgeo.x -= fact[Left];
|
||||
cgeo.width += fact[Left];
|
||||
|
||||
/* Top factor */
|
||||
cgeo.y -= fact[Top];
|
||||
cgeo.height += fact[Top];
|
||||
|
||||
/* Bottom factor */
|
||||
cgeo.height += fact[Bottom];
|
||||
|
||||
return cgeo;
|
||||
}
|
||||
|
||||
/** Manual resizing of tiled clients
|
||||
* \param c Client pointer
|
||||
* \param p Direction of resizing
|
||||
* \param fac Factor of resizing
|
||||
*/
|
||||
static void
|
||||
client_tile_factor_set(Client *c, Position p, int fac)
|
||||
{
|
||||
Client *gc = NULL;
|
||||
int x, y;
|
||||
XRectangle cgeo, scgeo;
|
||||
Position reversepos[4] = { Left, Right, Bottom, Top };
|
||||
int cfact[4] = { 0 }, scfact[4] = { 0 };
|
||||
char scanfac[4][3] =
|
||||
{
|
||||
{ 1, 0 }, { -1, 0 }, /* Right, Left */
|
||||
{ 0, -1 }, { 0, 1 } /* Top, Bottom */
|
||||
};
|
||||
|
||||
if(!c || p > Bottom)
|
||||
return;
|
||||
|
||||
/* Start place of pointer for faster scanning */
|
||||
x = c->geo.x + ((p == Right) ? c->geo.width : 0);
|
||||
y = c->geo.y + ((p == Bottom) ? c->geo.height : 0);
|
||||
y += ((p < Top) ? c->geo.height / 2 : 0);
|
||||
x += ((p > Left) ? c->geo.width / 2 : 0);
|
||||
|
||||
/* Scan in right direction to next(p) physical client */
|
||||
for(; (gc = client_gb_pos(c, x, y)) == c; x += scanfac[p][0], y += scanfac[p][1]);
|
||||
|
||||
if(!gc || c->screen != gc->screen)
|
||||
return;
|
||||
|
||||
cfact[p] += fac;
|
||||
scfact[reversepos[p]] -= fac;
|
||||
|
||||
cgeo = client_get_geo_factor(c->geo, cfact);
|
||||
scgeo = client_get_geo_factor(gc->geo, scfact);
|
||||
|
||||
/* Too big */
|
||||
if(scgeo.width > (1 << 15) || scgeo.height > (1 << 15)
|
||||
|| cgeo.width > (1 << 15) || cgeo.height > (1 << 15))
|
||||
return;
|
||||
|
||||
/* Too small */
|
||||
if(scgeo.width < 1 || scgeo.height < 1
|
||||
|| cgeo.width < 1 || cgeo.height < 1)
|
||||
return;
|
||||
|
||||
/* Check if move/resize is needed for same col/row clients */
|
||||
/*for(sc = tiled_client(c->screen, clients); sc; tiled_client(c->screen, c->next))
|
||||
if(sc->geo.*/
|
||||
|
||||
c->tilefact[p] += fac;
|
||||
gc->tilefact[reversepos[p]] -= fac;
|
||||
|
||||
/* Magic moment */
|
||||
client_moveresize(c, cgeo, tags[c->screen][c->tag].resizehint);
|
||||
client_moveresize(gc, scgeo, tags[gc->screen][gc->tag].resizehint);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
uicb_client_resize_right(uicb_t cmd)
|
||||
{
|
||||
int n = atoi(cmd);
|
||||
|
||||
CHECK(sel);
|
||||
|
||||
client_tile_factor_set(sel, Right, n);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
uicb_client_resize_left(uicb_t cmd)
|
||||
{
|
||||
int n = atoi(cmd);
|
||||
|
||||
CHECK(sel);
|
||||
|
||||
client_tile_factor_set(sel, Left, n);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
uicb_client_resize_top(uicb_t cmd)
|
||||
{
|
||||
int n = atoi(cmd);
|
||||
|
||||
CHECK(sel);
|
||||
|
||||
client_tile_factor_set(sel, Top, n);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
uicb_client_resize_bottom(uicb_t cmd)
|
||||
{
|
||||
int n = atoi(cmd);
|
||||
|
||||
CHECK(sel);
|
||||
|
||||
client_tile_factor_set(sel, Bottom, n);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -273,7 +273,7 @@ grid(int screen, Bool horizontal)
|
||||
c->flags |= TileFlag;
|
||||
++cpcols;
|
||||
|
||||
client_clean_tile_fact(c);
|
||||
cfactor_clean(c);
|
||||
|
||||
cgeo.width = (sg.width / cols) - (BORDH * 2);
|
||||
cgeo.height = (sg.height / rows) - BORDH;
|
||||
@ -361,7 +361,7 @@ multi_tile(int screen, Position type)
|
||||
c->flags &= ~(MaxFlag | LMaxFlag);
|
||||
c->flags |= TileFlag;
|
||||
|
||||
client_clean_tile_fact(c);
|
||||
cfactor_clean(c);
|
||||
|
||||
/* MASTER */
|
||||
if(i < nmaster)
|
||||
@ -519,7 +519,7 @@ mirror(int screen, Bool horizontal)
|
||||
c->flags &= ~(MaxFlag | LMaxFlag);
|
||||
c->flags |= TileFlag;
|
||||
|
||||
client_clean_tile_fact(c);
|
||||
cfactor_clean(c);
|
||||
|
||||
if(i < nmaster)
|
||||
{
|
||||
|
||||
14
src/wmfs.h
14
src/wmfs.h
@ -152,6 +152,14 @@ void uicb_infobar_togglepos(uicb_t);
|
||||
void uicb_infobar_toggledisplay(uicb_t);
|
||||
void uicb_toggle_tagautohide(uicb_t);
|
||||
|
||||
/* cfactor.c */
|
||||
void cfactor_clean(Client *c);
|
||||
XRectangle cfactor_geo(XRectangle geo, int fact[4]);
|
||||
void uicb_client_resize_right(uicb_t cmd);
|
||||
void uicb_client_resize_left(uicb_t cmd);
|
||||
void uicb_client_resize_top(uicb_t cmd);
|
||||
void uicb_client_resize_bottom(uicb_t cmd);
|
||||
|
||||
/* client.c */
|
||||
void client_attach(Client *c);
|
||||
void client_configure(Client *c);
|
||||
@ -183,8 +191,6 @@ void client_unmanage(Client *c);
|
||||
void client_unmap(Client *c);
|
||||
void client_update_attributes(Client *c);
|
||||
void client_urgent(Client *c, Bool u);
|
||||
void client_clean_tile_fact(Client *c);
|
||||
XRectangle client_get_geo_factor(XRectangle geo, int fact[4]);
|
||||
void uicb_client_raise(uicb_t);
|
||||
void uicb_client_next(uicb_t);
|
||||
void uicb_client_prev(uicb_t);
|
||||
@ -205,10 +211,6 @@ void uicb_clientlist(uicb_t cmd);
|
||||
Bool uicb_checkclist(uicb_t);
|
||||
void uicb_client_ignore_tag(uicb_t);
|
||||
void uicb_client_set_master(uicb_t);
|
||||
void uicb_client_resize_right(uicb_t cmd);
|
||||
void uicb_client_resize_left(uicb_t cmd);
|
||||
void uicb_client_resize_top(uicb_t cmd);
|
||||
void uicb_client_resize_bottom(uicb_t cmd);
|
||||
|
||||
/* ewmh.c */
|
||||
void ewmh_init_hints(void);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user