From wlst-xmonad at zruze.cz Fri Apr 3 14:45:35 2020 From: wlst-xmonad at zruze.cz (Michal J.) Date: Fri, 3 Apr 2020 16:45:35 +0200 Subject: [xmonad] A proper way to make XMonad.Actions.WindowMenu configurable? Message-ID: <20200403144535.GA5038@prdell.home.wejn.org> Hello friendly folks, I'm a relative newb to both xmonad and Haskell, and for a while I wrestled with a seemingly simple task -- to make XMonad.Actions.WindowMenu (from xmonad-contrib) configurable. Essentially I wanted to go from: windowMenu :: X () windowMenu = ... to: windowMenu :: ??? -> X () windowMenu actions = ... so I can customize the actions that pop up. So I can bind different menus to different key combos. Now, I documented some of my struggles at Stack Overflow: https://stackoverflow.com/q/61001342/1177128 and eventually came up with a solution (with help from others!): https://stackoverflow.com/a/61013887/1177128 But given that grepping the xmonad and xmonad-contrib sources for ":: XConf ->" returns exactly 1 result (spoiler: `runX` in `Core.hs`), I'm pretty sure I'm holding it wrong: ```haskell defaultActions :: XConf -> [(String, X ())] defaultActions = do tags <- asks (workspaces . config) return ([ ("Cancel menu", return ()) , ("Close" , kill) , ("Maximize" , withFocused $ \w -> sendMessage $ maximizeRestore w) , ("Minimize" , withFocused $ \w -> minimizeWindow w) ] ++ [ ("Move to " ++ tag, windows $ W.shift tag) | tag <- tags ]) windowMenu' :: (XConf -> [(String, X ())]) -> X () windowMenu' actions = withFocused $ \w -> do acts <- asks actions Rectangle x y wh ht <- getSize w Rectangle sx sy swh sht <- gets $ screenRect . W.screenDetail . W.current . windowset let originFractX = (fi x - fi sx + fi wh / 2) / fi swh originFractY = (fi y - fi sy + fi ht / 2) / fi sht gsConfig = (buildDefaultGSConfig colorizer) { gs_originFractX = originFractX , gs_originFractY = originFractY } runSelectedAction gsConfig acts -- now it composes well, and I can pass in my own `actions` to `windowMenu` windowMenu = windowMenu' defaultActions ``` Can anyone well versed in the idiosyncrasies of Haskell and XMonad please point out what would be the proper -- nay, canonical -- solution if it were done by someone who actually knows what they're doing? It'd be greatly appreciated. :-) Cheers, Michal PS: If the refactor seems like I really have no clue what's going on... well... I don't. And if you have a pointer to some text I should read to understand all this better, I'm all ears. From allbery.b at gmail.com Sun Apr 5 13:39:59 2020 From: allbery.b at gmail.com (Brandon Allbery) Date: Sun, 5 Apr 2020 09:39:59 -0400 Subject: [xmonad] A proper way to make XMonad.Actions.WindowMenu configurable? In-Reply-To: <20200403144535.GA5038@prdell.home.wejn.org> References: <20200403144535.GA5038@prdell.home.wejn.org> Message-ID: For what it's worth, you normally get the XConf via `ask` (Control.Monad.Reader) instead of passing it around. The primary exception is in ManageHooks, which have a different Reader on top and you must use `liftX` first to get at the other one. Your own actions would not normally be part of the XConf or XConfig, but a separate type which you would pass around. Compare something like XMonad.Prompt and its `XPConfig` type. On Fri, Apr 3, 2020 at 10:46 AM Michal J. wrote: > Hello friendly folks, > > I'm a relative newb to both xmonad and Haskell, and for a while I > wrestled with a seemingly simple task -- to make XMonad.Actions.WindowMenu > (from xmonad-contrib) configurable. > > Essentially I wanted to go from: > > windowMenu :: X () > windowMenu = ... > > to: > > windowMenu :: ??? -> X () > windowMenu actions = ... > > so I can customize the actions that pop up. So I can bind different menus > to different key combos. > > Now, I documented some of my struggles at Stack Overflow: > https://stackoverflow.com/q/61001342/1177128 > and eventually came up with a solution (with help from others!): > https://stackoverflow.com/a/61013887/1177128 > > But given that grepping the xmonad and xmonad-contrib sources for > ":: XConf ->" returns exactly 1 result (spoiler: `runX` in `Core.hs`), I'm > pretty sure I'm holding it wrong: > > ```haskell > defaultActions :: XConf -> [(String, X ())] > defaultActions = do > tags <- asks (workspaces . config) > return ([ ("Cancel menu", return ()) > , ("Close" , kill) > , ("Maximize" , withFocused $ \w -> sendMessage $ > maximizeRestore w) > , ("Minimize" , withFocused $ \w -> minimizeWindow w) > ] ++ > [ ("Move to " ++ tag, windows $ W.shift tag) | tag <- tags ]) > > windowMenu' :: (XConf -> [(String, X ())]) -> X () > windowMenu' actions = withFocused $ \w -> do > acts <- asks actions > Rectangle x y wh ht <- getSize w > Rectangle sx sy swh sht <- gets $ screenRect . W.screenDetail . > W.current . windowset > let originFractX = (fi x - fi sx + fi wh / 2) / fi swh > originFractY = (fi y - fi sy + fi ht / 2) / fi sht > gsConfig = (buildDefaultGSConfig colorizer) > { gs_originFractX = originFractX > , gs_originFractY = originFractY } > runSelectedAction gsConfig acts > > -- now it composes well, and I can pass in my own `actions` to `windowMenu` > windowMenu = windowMenu' defaultActions > ``` > > Can anyone well versed in the idiosyncrasies of Haskell and XMonad please > point out what would be the proper -- nay, canonical -- solution if it were > done by someone who actually knows what they're doing? > > It'd be greatly appreciated. :-) > > Cheers, > > Michal > > PS: If the refactor seems like I really have no clue what's going on... > well... I don't. And if you have a pointer to some text I should > read to understand all this better, I'm all ears. > _______________________________________________ > xmonad mailing list > xmonad at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad > -- brandon s allbery kf8nh allbery.b at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From wlst-xmonad at zruze.cz Sun Apr 5 20:49:53 2020 From: wlst-xmonad at zruze.cz (Michal J.) Date: Sun, 5 Apr 2020 22:49:53 +0200 Subject: [xmonad] A proper way to make XMonad.Actions.WindowMenu configurable? In-Reply-To: References: <20200403144535.GA5038@prdell.home.wejn.org> Message-ID: <20200405204953.GA3474@prdell.home.wejn.org> Hi Brandon, > For what it's worth, you normally get the XConf via `ask` > (Control.Monad.Reader) instead of passing it around. The primary > exception is in ManageHooks, which have a different Reader on top and > you must use `liftX` first to get at the other one. Thanks for the clarification. I think it'll take me a bit more work (after finishing the "wikibook" about Haskell I started yesterday) to truly understand all this. I mean, I still don't understand how one goes from `X ()` to bunch of other -- more specific -- subtypes, but at this point I have a feeling that a few more (tens of) hours of study will get me there. > Your own actions would not normally be part of the XConf or XConfig, > but a separate type which you would pass around. Yeah, another kind soul at SO pointed out my folly: https://stackoverflow.com/a/61019840/1177128 and basically told me how to convert my (apparently "bonkers") solution into something that's more understandable (and ~matches what you said): ```haskell -- details at the abovementioned link defaultActions :: X [(String, X ())] windowMenu' :: [(String, X ())] -> X () windowMenu :: X () windowMenu = defaultActions >>= windowMenu' ``` > Compare something like XMonad.Prompt and its `XPConfig` type. Thanks for the pointer. :-) Cheers, Michal From platon7pronko at gmail.com Fri Apr 17 19:08:02 2020 From: platon7pronko at gmail.com (Platon Pronko) Date: Fri, 17 Apr 2020 22:08:02 +0300 Subject: [xmonad] why spawn (and safeSpawn, etc) use encodeString? Message-ID: Hi! I noticed that spawn mangled my unicode characters - instead of my unicode character the called program recieved garbage. Looking deeper I found out that spawn pre-processes the string with `encodeString` function. `encodeString` first converts [Char] into [Word8], and then converts each individual Word8 back into Char. Since unicode Char will be converted into multiple Word8, the resulting string would be quite different. Example: Prelude> import Codec.Binary.UTF8.String Prelude Codec.Binary.UTF8.String> encodeString "Ø" "\195\152" Prelude Codec.Binary.UTF8.String> putStrLn "Ø" Ø Prelude Codec.Binary.UTF8.String> putStrLn $ encodeString "Ø" ÃPrelude Codec.Binary.UTF8.String> Is there a reason why xmonad uses `encodeString` here? I implemented a copy of the function that doesn't use `encodeString`, seems to work okay: safeSpawnUnicode :: MonadIO m => FilePath -> [String] -> m () safeSpawnUnicode prog args = io $ void $ forkProcess $ do uninstallSignalHandlers _ <- createSession executeFile prog True args Nothing Best regards, Platon Pronko From gwern at gwern.net Fri Apr 17 19:37:17 2020 From: gwern at gwern.net (Gwern Branwen) Date: Fri, 17 Apr 2020 15:37:17 -0400 Subject: [xmonad] why spawn (and safeSpawn, etc) use encodeString? In-Reply-To: References: Message-ID: As one of the people responsible for that, the backstory is that at the time very long ago (2008?), it wasn't clear how to handle Unicode text in a cross-distro bugfree way while passing through a Haskell library like XMonad from a Prompt into X11 or the shell or applications, no one had the appetite to make an in-depth study of the various systems to figure out what exactly had to be done to handle ASCII & Unicode in a way that would be safe everywhere, and `encodeString` seemed to sorta work in most cases and be better that what came before. Since the Haskell and other ecosystems have gradually continued evolving (one hopes), it's possible that many Unicode-related issues have since quietly vanished, and XMonad could do something simpler and more correct than it does now; but one would need to investigate thoroughly on a couple systems before one could be sure it was safe to update `spawn` and all downstream users of `encodeString` etc, and no one has been willing to do so to the extent to make a change in the (generally very stable) HEAD. -- gwern https://www.gwern.net From platon7pronko at gmail.com Fri Apr 17 20:05:10 2020 From: platon7pronko at gmail.com (Platon Pronko) Date: Fri, 17 Apr 2020 23:05:10 +0300 Subject: [xmonad] why spawn (and safeSpawn, etc) use encodeString? In-Reply-To: References: Message-ID: Unfortunately I do not have access to many different systems - only the one I use now, Arch Linux. So I won't be able to test it thoroughly. But as a data point - on my machine Prompt returns UTF8 and that UTF8 can be safely passed into the executeFile call, without encodeString. Best regards, Platon Pronko On 2020-04-17 22:37, Gwern Branwen wrote: > As one of the people responsible for that, the backstory is that at > the time very long ago (2008?), it wasn't clear how to handle Unicode > text in a cross-distro bugfree way while passing through a Haskell > library like XMonad from a Prompt into X11 or the shell or > applications, no one had the appetite to make an in-depth study of the > various systems to figure out what exactly had to be done to handle > ASCII & Unicode in a way that would be safe everywhere, and > `encodeString` seemed to sorta work in most cases and be better that > what came before. > > Since the Haskell and other ecosystems have gradually continued > evolving (one hopes), it's possible that many Unicode-related issues > have since quietly vanished, and XMonad could do something simpler and > more correct than it does now; but one would need to investigate > thoroughly on a couple systems before one could be sure it was safe to > update `spawn` and all downstream users of `encodeString` etc, and no > one has been willing to do so to the extent to make a change in the > (generally very stable) HEAD. > From allbery.b at gmail.com Fri Apr 17 20:23:38 2020 From: allbery.b at gmail.com (Brandon Allbery) Date: Fri, 17 Apr 2020 16:23:38 -0400 Subject: [xmonad] why spawn (and safeSpawn, etc) use encodeString? In-Reply-To: References: Message-ID: In 2020 my inclination is to encode if it has codepoints > 255 in it and leave it on the user otherwise; it's impossible to guess the right action. On Fri, Apr 17, 2020, 16:05 Platon Pronko wrote: > Unfortunately I do not have access to many different systems - only the > one I use now, Arch Linux. So I won't be able to test it thoroughly. But as > a data point - on my machine Prompt returns UTF8 and that UTF8 can be > safely passed into the executeFile call, without encodeString. > > Best regards, > Platon Pronko > > On 2020-04-17 22:37, Gwern Branwen wrote: > > As one of the people responsible for that, the backstory is that at > > the time very long ago (2008?), it wasn't clear how to handle Unicode > > text in a cross-distro bugfree way while passing through a Haskell > > library like XMonad from a Prompt into X11 or the shell or > > applications, no one had the appetite to make an in-depth study of the > > various systems to figure out what exactly had to be done to handle > > ASCII & Unicode in a way that would be safe everywhere, and > > `encodeString` seemed to sorta work in most cases and be better that > > what came before. > > > > Since the Haskell and other ecosystems have gradually continued > > evolving (one hopes), it's possible that many Unicode-related issues > > have since quietly vanished, and XMonad could do something simpler and > > more correct than it does now; but one would need to investigate > > thoroughly on a couple systems before one could be sure it was safe to > > update `spawn` and all downstream users of `encodeString` etc, and no > > one has been willing to do so to the extent to make a change in the > > (generally very stable) HEAD. > > > _______________________________________________ > xmonad mailing list > xmonad at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad > -------------- next part -------------- An HTML attachment was scrubbed... URL: From agarciafdz at gmail.com Wed Apr 22 15:05:42 2020 From: agarciafdz at gmail.com (Alejandro Garcia) Date: Wed, 22 Apr 2020 10:05:42 -0500 Subject: [xmonad] How to trigger Xmonad.Prompt.AddFile on recurrent times? Message-ID: Hello In order to help with my personal productivity. I want to register what I'm doing every 15 minutes or so. And using Xmonad.Prompt.AddFile is very easy. Currently I launch it with a key combination and I can start writing what I'm doing in this moment. However, no I would like to automatically launch AddFile every 15 minutes... Ideally from cron (which I know) or maybe xmonad has a way to do it itself? -- Alejandro García F. (elviejo) Too brief? Here's why! http://emailcharter.org EOM – End Of Message. The whole message is in the subject don't need to open it. NNTR – No Need To Respond. Help cut down on all those “cool” and “thanks” emails. SINGLE SUBJECT. Send one email for one topic, this makes replies easy.. CLEAR CALL TO ACTION: Ask for some specific result very clearly. From platon7pronko at gmail.com Wed Apr 22 15:52:41 2020 From: platon7pronko at gmail.com (Platon Pronko) Date: Wed, 22 Apr 2020 18:52:41 +0300 Subject: [xmonad] How to trigger Xmonad.Prompt.AddFile on recurrent times? In-Reply-To: References: Message-ID: <54da1d3f-4154-0160-7968-f51883b5146b@gmail.com> Hi! I'm not an expert, but it seems that forking a thread inside XMonad itself wouldn't work - there is no function that will allow you to convert X () back to IO (), thus you can't use the usual forkIO calls. You can probably implement something via X events and server-mode hooks: https://hackage.haskell.org/package/xmonad-contrib-0.16/docs/XMonad-Hooks-ServerMode.html But may I suggest using a much simpler approach and skipping XMonad entirely? You can use for example `yad` or `zenity` to display a graphical input box directly from a script. For example something like the following: $ yad --text="Current activity:" --entry >> activity-log.txt Best regards, Platon Pronko On 2020-04-22 18:05, Alejandro Garcia wrote: > Hello In order to help with my personal productivity. > I want to register what I'm doing every 15 minutes or so. > > And using Xmonad.Prompt.AddFile is very easy. > Currently I launch it with a key combination and I can start writing > what I'm doing in this moment. > > However, no I would like to automatically launch AddFile every 15 minutes... > Ideally from cron (which I know) > or maybe xmonad has a way to do it itself? > > > From allbery.b at gmail.com Wed Apr 22 16:11:09 2020 From: allbery.b at gmail.com (Brandon Allbery) Date: Wed, 22 Apr 2020 12:11:09 -0400 Subject: [xmonad] How to trigger Xmonad.Prompt.AddFile on recurrent times? In-Reply-To: <54da1d3f-4154-0160-7968-f51883b5146b@gmail.com> References: <54da1d3f-4154-0160-7968-f51883b5146b@gmail.com> Message-ID: There are also time tracking programs for this. The way to do this inside xmonad is to send a ClientMessage event which is handled in the handleEventHook. You could send the event from a cron job, or fork a thread which opens its own server connection (X11 only pretends to be thread safe) and sends it after a delay. On Wed, Apr 22, 2020, 11:53 Platon Pronko wrote: > Hi! > > I'm not an expert, but it seems that forking a thread inside XMonad itself > wouldn't work - there is no function that will allow you to convert X () > back to IO (), thus you can't use the usual forkIO calls. > > You can probably implement something via X events and server-mode hooks: > https://hackage.haskell.org/package/xmonad-contrib-0.16/docs/XMonad-Hooks-ServerMode.html > > But may I suggest using a much simpler approach and skipping XMonad > entirely? You can use for example `yad` or `zenity` to display a graphical > input box directly from a script. For example something like the following: > > $ yad --text="Current activity:" --entry >> activity-log.txt > > Best regards, > Platon Pronko > > On 2020-04-22 18:05, Alejandro Garcia wrote: > > Hello In order to help with my personal productivity. > > I want to register what I'm doing every 15 minutes or so. > > > > And using Xmonad.Prompt.AddFile is very easy. > > Currently I launch it with a key combination and I can start writing > > what I'm doing in this moment. > > > > However, no I would like to automatically launch AddFile every 15 > minutes... > > Ideally from cron (which I know) > > or maybe xmonad has a way to do it itself? > > > > > > > _______________________________________________ > xmonad mailing list > xmonad at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nicholma at tcd.ie Wed Apr 22 17:59:09 2020 From: nicholma at tcd.ie (Matthew Nicholson) Date: Wed, 22 Apr 2020 18:59:09 +0100 Subject: [xmonad] How to trigger Xmonad.Prompt.AddFile on recurrent times? In-Reply-To: References: Message-ID: You could use xdotool, github.com/jordansissel/xdotool, to trigger the keyboard shortcut. For example `xdotool key super+f` fakes pressing the super key and f. On Wed, 22 Apr 2020 at 16:06, Alejandro Garcia wrote: > Hello In order to help with my personal productivity. > I want to register what I'm doing every 15 minutes or so. > > And using Xmonad.Prompt.AddFile is very easy. > Currently I launch it with a key combination and I can start writing > what I'm doing in this moment. > > However, no I would like to automatically launch AddFile every 15 > minutes... > Ideally from cron (which I know) > or maybe xmonad has a way to do it itself? > > > > -- > Alejandro García F. (elviejo) > > Too brief? Here's why! http://emailcharter.org > > EOM – End Of Message. The whole message is in the subject don't need to > open it. > NNTR – No Need To Respond. Help cut down on all those “cool” and > “thanks” emails. > SINGLE SUBJECT. Send one email for one topic, this makes replies easy.. > CLEAR CALL TO ACTION: Ask for some specific result very clearly. > _______________________________________________ > xmonad mailing list > xmonad at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vrs+xmonad at synkretie.net Sat Apr 25 00:08:37 2020 From: vrs+xmonad at synkretie.net (vrs) Date: Sat, 25 Apr 2020 02:08:37 +0200 Subject: [xmonad] How to trigger Xmonad.Prompt.AddFile on recurrent times? In-Reply-To: References: Message-ID: <158777331796.894434.2484458736404813854@tanha.noos.synkretie.net> Hi, I used to use arbtt for this kind of thing, you may want to check it out: https://arbtt.nomeata.de/ I only stopped using it because it turned out I didn't much care about the stats after all. But it did in fact work so well that I often forgot it existed. -vrs Quoting Alejandro Garcia (2020-04-22 17:05:42) > Hello In order to help with my personal productivity. > I want to register what I'm doing every 15 minutes or so. > > And using Xmonad.Prompt.AddFile is very easy. > Currently I launch it with a key combination and I can start writing > what I'm doing in this moment. > > However, no I would like to automatically launch AddFile every 15 minutes... > Ideally from cron (which I know) > or maybe xmonad has a way to do it itself? > > > > -- > Alejandro García F. (elviejo) > > Too brief? Here's why! http://emailcharter.org > > EOM – End Of Message. The whole message is in the subject don't need to open it. > NNTR – No Need To Respond. Help cut down on all those “cool” and > “thanks” emails. > SINGLE SUBJECT. Send one email for one topic, this makes replies easy.. > CLEAR CALL TO ACTION: Ask for some specific result very clearly. > _______________________________________________ > xmonad mailing list > xmonad at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad