From ef998ee445e8a59a1cc5c9d15d721aabea187fd7 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Thu, 2 Feb 2023 21:17:12 +1300 Subject: feat: fullscreen keybind --- config.toml | 3 +++ main.cpp | 44 ++++++++++++++++++++++++++++++++++++++------ notes.org | 16 ++++++++++------ structs.h | 1 + 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/config.toml b/config.toml index be0354f..682cda8 100644 --- a/config.toml +++ b/config.toml @@ -32,6 +32,9 @@ func = "kill" [[Keybinds.key]] bind = "mod+shift+r" func = "reload" +[[Keybinds.key]] +bind = "mod+f" +func = "fullscreen" #Focus [[Keybinds.key]] diff --git a/main.cpp b/main.cpp index d4502dd..6f1cd9b 100644 --- a/main.cpp +++ b/main.cpp @@ -75,6 +75,7 @@ int mX, mY; #define getClient(c) clients.find(c)->second #define getFrame(f) frames.find(f)->second +#define getFrameID(w) frameIDS.find(w)->second Window bar; @@ -95,9 +96,14 @@ void clientMessage(XClientMessageEvent e); static int OnXError(Display* display, XErrorEvent* e); +// Tiling +// Call this one to tile everything (it does all the fancy stuff trust me just call this one) void tileRoots(); +// Call this one to until everything (it handles multiple monitors) void untileRoots(); -void tile(int frameID, int x, int y, int w, int h); +// This is to be called by tileRoots, it takes in the x, y, w, and h of where it's allowed to tile windows to, and returns the ID of a fullscreen client if one is found, or noID (-1) if none are found +int tile(int frameID, int x, int y, int w, int h); +// This is to be called by tileRoots, it takes in a frameID and recursively unmaps all its children void untile(int frameID); // Usefull functions @@ -573,6 +579,17 @@ const void nextMonitor(const CommandArg* argv) XWarpPointer(dpy, root, root, 0, 0, 0, 0, screens[focusedScreen].x + screens[focusedScreen].w/2, screens[focusedScreen].y + screens[focusedScreen].h/2); focusRoot(focusedWorkspaces[focusedScreen]); } +void fullscreen(const KeyArg arg) +{ + Window focusedWindow; + int focusedRevert; + XGetInputFocus(dpy, &focusedWindow, &focusedRevert); + + int fID = getFrameID(focusedWindow); + int cID = getFrame(fID).cID; + getClient(cID).fullscreen ^= true; + tileRoots(); +} void configureRequest(XConfigureRequestEvent e) { @@ -670,7 +687,7 @@ void mapRequest(XMapRequestEvent e) XSelectInput(dpy, e.window, EnterWindowMask); //Make client - Client c = {currClientID, e.window, false}; + Client c = {currClientID, e.window, false, false}; currClientID++; //Add to clients map @@ -861,7 +878,17 @@ void tileRoots() { for(int i = 0; i < nscreens; i++) { - tile(focusedWorkspaces[i], screens[i].x + cfg.outerGaps, screens[i].y + cfg.outerGaps, screens[i].w - cfg.outerGaps*2, screens[i].h - cfg.outerGaps*2 - bH); + int fullscreenClientID = tile(focusedWorkspaces[i], screens[i].x + cfg.outerGaps, screens[i].y + cfg.outerGaps, screens[i].w - cfg.outerGaps*2, screens[i].h - cfg.outerGaps*2 - bH); + if(fullscreenClientID!=noID) + { + untile(focusedWorkspaces[i]); + Client c = getClient(fullscreenClientID); + XMapWindow(dpy, c.w); + XMoveWindow(dpy, c.w, + screens[i].x, screens[i].y); + XResizeWindow(dpy, c.w, + screens[i].w, screens[i].h); + } } } void untileRoots() @@ -871,7 +898,7 @@ void untileRoots() untile(focusedWorkspaces[i]); } } -void tile(int frameID, int x, int y, int w, int h) +int tile(int frameID, int x, int y, int w, int h) { for(int fID : frames.find(frameID)->second.floatingFrameIDs) { @@ -896,20 +923,25 @@ void tile(int frameID, int x, int y, int w, int h) } if(!f.isClient) { - tile(fID, wX, wY, wW, wH); + int fullscreenClientID = tile(fID, wX, wY, wW, wH); + if(fullscreenClientID == noID) + return fullscreenClientID; continue; } + Client c = clients.find(f.cID)->second; + if(c.fullscreen) + return c.ID; wX += cfg.gaps; wY += cfg.gaps; wW -= cfg.gaps * 2; wH -= cfg.gaps * 2; - Client c = clients.find(f.cID)->second; XMapWindow(dpy, c.w); XMoveWindow(dpy, c.w, wX, wY); XResizeWindow(dpy, c.w, wW, wH); } + return noID; } void untile(int frameID) diff --git a/notes.org b/notes.org index a3b6bf1..ec19667 100644 --- a/notes.org +++ b/notes.org @@ -1,5 +1,10 @@ #+TITLE: Features to add +* Main refactor for the future +** Make it possible to split up the code into mulitple files easier +- Header files for some functions such as ~tileRoots~, potentially classes as well +- Main variables like the list of clients as a stuct, pointer can then be passed for things like EWMH + * Remembering focus Use the variable ~whichChildFocused~ for each non client frame, this is the index of the child that is focused. To then find focused child for a root recurse through all the frames going through the focused child. ** Where it should be updated @@ -9,18 +14,17 @@ Use the variable ~whichChildFocused~ for each non client frame, this is the inde ** Where it should be used Whenever I set focus I should use the focused client of whichever workspace is focused -* Change focus and move between monitors -Perhaps I can just add something to the ~dirFind~ function - -* TOML config -put in ~/.config/YATwm/config.toml +* Config +rewrite it to be a scripting language like i3 * Fullscreen windows This should be another thing like floating windows except each workspace only gets one I should check it first when tiling and if it exists then draw it to the size of the screeen then return * General EWMH things -I should really figure out what all the client messages mean +** I should really figure out what all the client messages mean +- ~_NET_WM_STATE~ is used to change a windows state e.g. moving to fullscreen. It is an ~Atom[]~ * The eventual program to communicate with YATwm Use a unix socket +Same protocol as config langauge diff --git a/structs.h b/structs.h index 0ace524..8215bf5 100644 --- a/structs.h +++ b/structs.h @@ -13,6 +13,7 @@ struct Client int ID; Window w; bool floating; + bool fullscreen; }; enum TileDir -- cgit v1.2.3 From ab3d823a8190ae6ec4a1444aa3b5a01aaa018586 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Fri, 3 Feb 2023 17:45:07 +1300 Subject: feat: Windows that request to be fullscreen should become fullscreen - more testing neededs --- ewmh.cpp | 12 ++++++++++++ ewmh.h | 2 ++ main.cpp | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/ewmh.cpp b/ewmh.cpp index 5a7e76c..5878e82 100644 --- a/ewmh.cpp +++ b/ewmh.cpp @@ -65,6 +65,18 @@ void setCurrentDesktop(int desktop) XChangeProperty(*dpy_, *root_, netCurrentDesktop, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&currDesktop, 1); } +void setFullscreen(Window w, bool fullscreen) +{ + Atom netWMState = XInternAtom(*dpy_, "_NET_WM_STATE", true); + Atom netWMStateVal; + if(fullscreen) + netWMStateVal = XInternAtom(*dpy_, "_NET_WM_STATE_FULLSCREEN", true); + else + netWMStateVal = XInternAtom(*dpy_, "", true); + XChangeProperty(*dpy_, w, netWMState, XA_ATOM, 32, PropModeReplace, (unsigned char*)&netWMStateVal, 1); + +} + int getProp(Window w, char* propName, Atom* type, unsigned char** data) { Atom prop_type = XInternAtom(*dpy_, propName, false); diff --git a/ewmh.h b/ewmh.h index 5fbc9a4..e8bae0c 100644 --- a/ewmh.h +++ b/ewmh.h @@ -18,4 +18,6 @@ void setWindowDesktop(Window w, int desktop); void setCurrentDesktop(int desktop); +void setFullscreen(Window w, bool fullscreen); + int getProp(Window w, char* propName, Atom* type, unsigned char** data); diff --git a/main.cpp b/main.cpp index 6f1cd9b..01f01c7 100644 --- a/main.cpp +++ b/main.cpp @@ -589,6 +589,7 @@ void fullscreen(const KeyArg arg) int cID = getFrame(fID).cID; getClient(cID).fullscreen ^= true; tileRoots(); + setFullscreen(focusedWindow, getClient(cID).fullscreen); } void configureRequest(XConfigureRequestEvent e) @@ -862,6 +863,26 @@ void clientMessage(XClientMessageEvent e) setCurrentDesktop(currWS); */ } + else if(e.message_type == XInternAtom(dpy, "_NET_WM_STATE", false)) + { + if((Atom)e.data.l[0] == 0) + log("\tremove"); + if((Atom)e.data.l[0] == 1) + log("\ttoggle"); + if((Atom)e.data.l[0] == 2) + log("\tadd"); + char* prop1 = XGetAtomName(dpy, (Atom)e.data.l[1]); + log("\tprop1"); + if((Atom)e.data.l[1] == XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", false)) + { + int fID = getFrameID(e.window); + int cID = getFrame(fID).cID; + getClient(cID).fullscreen = (Atom) e.data.l[0] == 1; + setFullscreen(e.window, (Atom) e.data.l[0] == 1); + tileRoots(); + } + XFree(prop1); + } XFree(name); } -- cgit v1.2.3 From 21b1840e0982929c1fa8acc5fadd203dccc94585 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 25 Feb 2023 17:07:29 +1300 Subject: fixup: Make fullscreen request either toggle or add I'm not sure if add prop is ever going to be used though. I've tested with both OBS and qutebrowser and both send 2 toggle requests to go fullscreen, and 2 remove requests to get out of fullscreen --- main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 01f01c7..af9210b 100644 --- a/main.cpp +++ b/main.cpp @@ -872,13 +872,12 @@ void clientMessage(XClientMessageEvent e) if((Atom)e.data.l[0] == 2) log("\tadd"); char* prop1 = XGetAtomName(dpy, (Atom)e.data.l[1]); - log("\tprop1"); if((Atom)e.data.l[1] == XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", false)) { int fID = getFrameID(e.window); int cID = getFrame(fID).cID; - getClient(cID).fullscreen = (Atom) e.data.l[0] == 1; - setFullscreen(e.window, (Atom) e.data.l[0] == 1); + getClient(cID).fullscreen = (Atom) e.data.l[0] > 0; + setFullscreen(e.window, (Atom) e.data.l[0] > 0); tileRoots(); } XFree(prop1); -- cgit v1.2.3 From c4813b0ad3f8e0cc4f55b0f0fda8359eb9729417 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Wed, 21 Jun 2023 20:26:52 +1200 Subject: feat: Fixed fullscreen stuff after rebasing in the config refactor Also added stuff to the readme for it --- config | 2 + config.toml | 190 ------------------------------------------------------------ main.cpp | 3 +- readme.html | 82 +++++++++++++------------- readme.org | 2 + 5 files changed, 48 insertions(+), 231 deletions(-) delete mode 100644 config.toml diff --git a/config b/config index f97bb04..b154600 100644 --- a/config +++ b/config @@ -8,6 +8,7 @@ bind mod+Return spawn alacritty bind mod+c spawn firefox bind mod+x spawn loginctl lock-session bind mod+shift+x bashSpawn loginctl lock-session && systemctl suspend +bind mod+d bashSpawn "rofi -i -show drun" gaps 10 outergaps 10 @@ -16,6 +17,7 @@ bind mod+q kill # Tiling bind mod+t toggle +bind mod+f fullscreen # Focus bind mod+h focChange left diff --git a/config.toml b/config.toml deleted file mode 100644 index 682cda8..0000000 --- a/config.toml +++ /dev/null @@ -1,190 +0,0 @@ -[Startup] -startupBash = [ -# "emacs --daemon" -] - -[Main] -gaps = 3 -outerGaps = 3 -logFile = "/tmp/yatlog.txt" - -[Workspaces] -numWS = 10 -workspaceNames = ["1: ", "2: 拾", "3: ", "4: ", "5: ", "6: ", "7: 拾", "8: ", "9: ", "10: "] -maxMonitors = 2 -screenPreferences = [[0], [0], [0], [0], [0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0]] - -[Keybinds] -swapSuperAlt = false - -# All the keybinds - -#General -[[Keybinds.key]] -bind = "mod+e" -func = "exit" -[[Keybinds.key]] -bind = "mod+t" -func = "toggle" -[[Keybinds.key]] -bind = "mod+q" -func = "kill" -[[Keybinds.key]] -bind = "mod+shift+r" -func = "reload" -[[Keybinds.key]] -bind = "mod+f" -func = "fullscreen" - -#Focus -[[Keybinds.key]] -bind = "mod+h" -func = "focChange" -args = "Left" -[[Keybinds.key]] -bind = "mod+j" -func = "focChange" -args = "Down" -[[Keybinds.key]] -bind = "mod+k" -func = "focChange" -args = "Up" -[[Keybinds.key]] -bind = "mod+l" -func = "focChange" -args = "Right" -[[Keybinds.key]] -bind = "alt+Tab" -func = "nextMonitor" - -#Window moving -[[Keybinds.key]] -bind = "mod+shift+h" -func = "wMove" -args = "Left" -[[Keybinds.key]] -bind = "mod+shift+j" -func = "wMove" -args = "Down" -[[Keybinds.key]] -bind = "mod+shift+k" -func = "wMove" -args = "Up" -[[Keybinds.key]] -bind = "mod+shift+l" -func = "wMove" -args = "Right" - - -#Spawning -[[Keybinds.key]] -bind = "mod+Return" -func = "spawn" -args = "alacritty" -[[Keybinds.key]] -bind = "mod+d" -func = "spawn" -args = "rofi -i -show drun" -[[Keybinds.key]] -bind = "mod+c" -func = "spawn" -args = "firefox" -[[Keybinds.key]] -bind = "mod+x" -func = "spawn" -args = "i3lock" -[[Keybinds.key]] -bind = "mod+shift+x" -func = "spawn" -args = "i3lock" -[[Keybinds.key]] -bind = "mod+shift+x" -func = "spawn" -args = "systemctl suspend" - -#Testing -[[Keybinds.key]] -bind = "mod+p" -func = "wsDump" - -# Workspace changing -[[Keybinds.key]] -bind = "mod+1" -func = "changeWS" -args = 1 -[[Keybinds.key]] -bind = "mod+1" -func = "wToWS" -args = 1 -[[Keybinds.key]] -bind = "mod+2" -func = "changeWS" -args = 2 -[[Keybinds.key]] -bind = "mod+2" -func = "wToWS" -args = 2 -[[Keybinds.key]] -bind = "mod+3" -func = "changeWS" -args = 3 -[[Keybinds.key]] -bind = "mod+3" -func = "wToWS" -args = 3 -[[Keybinds.key]] -bind = "mod+4" -func = "changeWS" -args = 4 -[[Keybinds.key]] -bind = "mod+4" -func = "wToWS" -args = 4 -[[Keybinds.key]] -bind = "mod+5" -func = "changeWS" -args = 5 -[[Keybinds.key]] -bind = "mod+5" -func = "wToWS" -args = 5 -[[Keybinds.key]] -bind = "mod+6" -func = "changeWS" -args = 6 -[[Keybinds.key]] -bind = "mod+6" -func = "wToWS" -args = 6 -[[Keybinds.key]] -bind = "mod+7" -func = "changeWS" -args = 7 -[[Keybinds.key]] -bind = "mod+7" -func = "wToWS" -args = 7 -[[Keybinds.key]] -bind = "mod+8" -func = "changeWS" -args = 8 -[[Keybinds.key]] -bind = "mod+8" -func = "wToWS" -args = 8 -[[Keybinds.key]] -bind = "mod+9" -func = "changeWS" -args = 9 -[[Keybinds.key]] -bind = "mod+9" -func = "wToWS" -args = 9 -[[Keybinds.key]] -bind = "mod+0" -func = "changeWS" -args = 10 -[[Keybinds.key]] -bind = "mod+0" -func = "wToWS" -args = 10 diff --git a/main.cpp b/main.cpp index af9210b..72ba368 100644 --- a/main.cpp +++ b/main.cpp @@ -579,7 +579,7 @@ const void nextMonitor(const CommandArg* argv) XWarpPointer(dpy, root, root, 0, 0, 0, 0, screens[focusedScreen].x + screens[focusedScreen].w/2, screens[focusedScreen].y + screens[focusedScreen].h/2); focusRoot(focusedWorkspaces[focusedScreen]); } -void fullscreen(const KeyArg arg) +const void fullscreen(const CommandArg* arg) { Window focusedWindow; int focusedRevert; @@ -1018,6 +1018,7 @@ int main(int argc, char** argv) commandsModule.addCommand("reload", reload, 0, {}); commandsModule.addCommand("wsDump", wsDump, 0, {}); commandsModule.addCommand("nextMonitor", nextMonitor, 0, {}); + commandsModule.addCommand("fullscreen", fullscreen, 0, {}); //Config std::vector cfgErr; diff --git a/readme.html b/readme.html index 24514ae..1040470 100644 --- a/readme.html +++ b/readme.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + YATwm @@ -200,36 +200,36 @@

Table of Contents

-
-

1. This config is best read in Emacs!

+
+

1. This config is best read in Emacs!

-
-

2. Disclaimer: This is still very much in beta

+
+

2. Disclaimer: This is still very much in beta

This only just works, multiple monitors aren't supported and floating windows cannot move and there is no resizing. Many features are just hacked together and are likely to break. However, it is just about usable so if you really want to try then go for it! (feel free to make an issue if you have any questions).
@@ -237,16 +237,16 @@ This only just works, multiple monitors aren't supported and floating windows ca

-
-

3. Usage instructions

+
+

3. Usage instructions

-
-

3.1. Installation

+
+

3.1. Installation

-
-

3.1.1. Pre reqs

+
+

3.1.1. Pre reqs

  • Xlib and g++ and libnotify to build the program
  • @@ -258,8 +258,8 @@ This only just works, multiple monitors aren't supported and floating windows ca
-
-

3.1.2. Installing and removing

+
+

3.1.2. Installing and removing

  • make i or make install to install
  • @@ -269,23 +269,23 @@ This only just works, multiple monitors aren't supported and floating windows ca
-
-

3.2. Config

+
+

3.2. Config

You can configure YATwm with the config file in $HOME/.config/YATwm/config or $XDG_CONFIG_HOME/YATwm/config if you have that set. I have provided an example config file in the project dir that has all the variables set to their defaults (this will also be installed to /etc/YATwm/config.
It should alert you with a notification if you have an error, and put the error your log file. If the whole file is missing then it will use the default in /etc/YATwm/config.

-
-

3.2.1. Syntax

+
+

3.2.1. Syntax

The config file is a list of commands. Each command should be on a new line. For example, to set the gaps you would use the gaps command like this gaps 10 (make sure this is all there is on that line). This says to call the command gaps with the arguments of 10. Commands can have multiple arguments and these should be separated with a space, if you want a space in one of the arguments then wrap the arg in quotes, e.g. addWorkspace "1: A" 1, here the arguments are 1: A and 1. If you want to have a quote in your argument then make sure that arg is wrapped in quotes or escape it with \ (e.g. \'), to insert \ then use \\.

    -
  1. Command arg types
    +
  2. Command arg types
    • String: this is just some text, this can be wrapped in quotes if you want a space in it.
    • @@ -302,7 +302,7 @@ The config file is a list of commands. Each command should be on a new line. For
  3. -
  4. List of commands
    +
  5. List of commands
    • exit: shuts down YATwm
    • @@ -338,6 +338,7 @@ The config file is a list of commands. Each command should be on a new line. For
  6. reload: Reloads YATwm, this reloads the config file and re runs the monitor detection, and will unmap and remap all windows to refresh them.
  7. nextMonitor: Focuses the next monitor, wraps around.
  8. +
  9. fullscreen: Toggles if the current window is fullscreen
  10. gaps: Sets the size of the inner gaps, margins around each window (this ends up looking doubled as each window has it)
    • Number: The size in pixels
    • @@ -367,8 +368,8 @@ The config file is a list of commands. Each command should be on a new line. For
-
-

3.2.2. General

+
+

3.2.2. General

You can change either the inner gaps (padding around each window - so double it for space between windows), or the outer gaps (padding around the display - add to inner gaps to get space between window and screen edges).
@@ -378,8 +379,8 @@ YATwm also keeps a log file, the location of this file can be changed with the c

-
-

3.2.3. Workspaces

+
+

3.2.3. Workspaces

You can add workspace with the command addworkspace in the config file.
@@ -405,8 +406,8 @@ Defaults workspace are listed below (these are the args for the addworkspace com

-
-

3.2.4. Keybinds

+
+

3.2.4. Keybinds

Current keybinds (these can all be edited):
@@ -423,6 +424,7 @@ Current keybinds (these can all be edited):

  • mod + c : firefox
  • mod + x : lock
  • mod + shift + x : lock and sleep
  • +
  • mod + f : toggle fullscreen
  • mod + (num) : switch to workspace (num) - currently only for 1-10 but you can add more
  • mod + shift + (num) : move window to workspace (num) - currently only for 1-10 but you can add more
  • @@ -449,8 +451,8 @@ Commands are executed going down the list and multiple commands with the same ke
    -
    -

    4. Credits

    +
    +

    4. Credits

    Catwm (https://github.com/pyknite/catwm)
    @@ -463,7 +465,7 @@ basicwm (https://github

    diff --git a/readme.org b/readme.org index 4f8afa1..9a41662 100644 --- a/readme.org +++ b/readme.org @@ -51,6 +51,7 @@ The config file is a list of commands. Each command should be on a new line. For - String rest: A string which gets sent to bash - reload: Reloads YATwm, this reloads the config file and re runs the monitor detection, and will unmap and remap all windows to refresh them. - nextMonitor: Focuses the next monitor, wraps around. +- fullscreen: Toggles if the current window is fullscreen - gaps: Sets the size of the inner gaps, margins around each window (this ends up looking doubled as each window has it) - Number: The size in pixels - outergaps: Sets the size of the outer gaps, distance for windows and the edge of the output (add this to the inner gaps to get distance between window and edge of output) @@ -100,6 +101,7 @@ Current keybinds (these can all be edited): - ~mod + c~ : firefox - ~mod + x~ : lock - ~mod + shift + x~ : lock and sleep +- ~mod + f~ : toggle fullscreen - ~mod + (num)~ : switch to workspace (num) - currently only for 1-10 but you can add more - ~mod + shift + (num)~ : move window to workspace (num) - currently only for 1-10 but you can add more (mod is super, and the direction keys are h, j, k, l - left, down, up, right respectively like vim) -- cgit v1.2.3