Re: [dev] Announcing a couple small X11 utilities

2023-08-01 Thread Yan Doroshenko

Hello,


I've addressed most of your concerns, please check the attached patch 
and let me know what else can be done.



Regards,

Yan


On 7/31/23 11:44, NRK wrote:

Hi Yan,

On Sat, Jul 29, 2023 at 02:46:29PM +0200, Yan Doroshenko wrote:

I've created a patch for sxot that adds a -m (--monitor) param that allows
to select which monitor to capture in a multihead setup. Let me know what
you think.

Thanks for the patch, I don't use a multimonitor setup to test it out
properly, but there are already a couple things which aren't too good.

+   int m[1];
+   str_to_int(str_from_cstr(argv[++i]), m);

str_to_int() does certain error checking (such as overflow) and returns
false in case of failure. That return value should not be ignored. It
should fatally error out if str_to_int() returns false.

It's also weird to use `int m[1]` instead of using `int m` and then
taking a pointer.

+   XRRScreenResources *screen;
+   screen = XRRGetScreenResources (x11.dpy, 
DefaultRootWindow(x11.dpy));

I'm not familiar with Xrander (and my local manpage is lacking
documentation for this function) but given that it returns a pointer, it
most likely needs to be error checked.

+   XRRCrtcInfo *crtc_info;
+   crtc_info = XRRGetCrtcInfo (x11.dpy, screen, 
screen->crtcs[m[0]]);

Same here, most likely needs error checking. But even more importantly:

screen->crtcs[m[0]]

one can never assume anything about data that came from outside. There's
no guarantee that m[0] won't be bigger than the len of `screen->crtcs`.

I see that there's a `ncrtc` member, which likely contains the len of
`crtcs`. You should check to make sure that it doesn't exceed that.

If you compile with AddressSanitizer (see the "recommended debug build"
on the README) and input some absurdly high value, you'll notice the
buffer overflow:

$ ./sxot -m 1024 >/dev/null
=
==11432==ERROR: AddressSanitizer: heap-buffer-overflow on address 
0x61a02600 at pc 0x00404271 bp 0x7ffe95aa74a0 sp 0x7ffe95aa7498

And even if you enter a valid value, ASan reports 2 leaks (output
cleaned up):

$ ./sxot -m 0 >/dev/null
SUMMARY: AddressSanitizer: 1296 byte(s) leaked in 2 allocation(s).

So something probably needs to be freed above.

- NRK

diff --git a/sxot.c b/sxot.c
index de87126..094cd7b 100644
--- a/sxot.c
+++ b/sxot.c
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 
 typedef uint8_t u8;
 typedef uint32_tu32;
@@ -207,7 +208,8 @@ main(int argc, char *argv[])
 		"usage: sxot [options]\n"
 		"Options:\n"
 		"  -g, --geomCapture the specified rectangle\n"
-		"  -c, --curosr   Capture the cursor also\n"
+		"  -c, --cursor   Capture the cursor also\n"
+		"  -m, --monitor nCapture the specified monitor\n"
 	);
 	Str version = S(
 		"sxot " VERSION "\n"
@@ -237,6 +239,38 @@ main(int argc, char *argv[])
 			if (!parse_geom(opt.v, str_from_cstr(argv[++i]))) {
 fatal(S("invalid geometry\n"));
 			}
+
+		} else if (str_eq(arg, S("--monitor")) || str_eq(arg, S("-m"))) {
+			int m;
+			if (!str_to_int(str_from_cstr(argv[++i]), )) {
+fatal(S("invalid monitor number\n"));
+			}
+
+			int n;
+			XRRMonitorInfo *monitors;
+			monitors = XRRGetMonitors(x11.dpy, x11.root, true, );
+
+			free(monitors);
+
+			if (n == -1) {
+fatal(S("get monitors failed\n"));
+			}
+			if (m >= n) {
+fatal(S("no monitor with such index\n"));
+			}
+
+			XRRScreenResources *screen;
+			screen = XRRGetScreenResources(x11.dpy, DefaultRootWindow(x11.dpy));
+			XRRCrtcInfo *crtc_info;
+			crtc_info = XRRGetCrtcInfo(x11.dpy, screen, screen->crtcs[m]);
+
+			opt.x = crtc_info->x;
+			opt.y = crtc_info->y;
+			opt.h = crtc_info->height;
+			opt.w = crtc_info->width;
+
+			free(crtc_info);
+			free(screen);
 		} else if (str_eq(arg, S("--cursor")) || str_eq(arg, S("-c"))) {
 			opt.capture_cursor = true;
 		} else if (str_eq(arg, S("--help")) || str_eq(arg, S("-h"))) {


OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: [dev] Announcing a couple small X11 utilities

2023-07-31 Thread Yan Doroshenko

On 7/31/23 11:44, NRK wrote:

Hi Yan,

On Sat, Jul 29, 2023 at 02:46:29PM +0200, Yan Doroshenko wrote:

I've created a patch for sxot that adds a -m (--monitor) param that allows
to select which monitor to capture in a multihead setup. Let me know what
you think.

Thanks for the patch, I don't use a multimonitor setup to test it out
properly, but there are already a couple things which aren't too good.

+   int m[1];
+   str_to_int(str_from_cstr(argv[++i]), m);

str_to_int() does certain error checking (such as overflow) and returns
false in case of failure. That return value should not be ignored. It
should fatally error out if str_to_int() returns false.

It's also weird to use `int m[1]` instead of using `int m` and then
taking a pointer.

+   XRRScreenResources *screen;
+   screen = XRRGetScreenResources (x11.dpy, 
DefaultRootWindow(x11.dpy));

I'm not familiar with Xrander (and my local manpage is lacking
documentation for this function) but given that it returns a pointer, it
most likely needs to be error checked.

+   XRRCrtcInfo *crtc_info;
+   crtc_info = XRRGetCrtcInfo (x11.dpy, screen, 
screen->crtcs[m[0]]);

Same here, most likely needs error checking. But even more importantly:

screen->crtcs[m[0]]

one can never assume anything about data that came from outside. There's
no guarantee that m[0] won't be bigger than the len of `screen->crtcs`.

I see that there's a `ncrtc` member, which likely contains the len of
`crtcs`. You should check to make sure that it doesn't exceed that.

If you compile with AddressSanitizer (see the "recommended debug build"
on the README) and input some absurdly high value, you'll notice the
buffer overflow:

$ ./sxot -m 1024 >/dev/null
=
==11432==ERROR: AddressSanitizer: heap-buffer-overflow on address 
0x61a02600 at pc 0x00404271 bp 0x7ffe95aa74a0 sp 0x7ffe95aa7498

And even if you enter a valid value, ASan reports 2 leaks (output
cleaned up):

$ ./sxot -m 0 >/dev/null
SUMMARY: AddressSanitizer: 1296 byte(s) leaked in 2 allocation(s).

So something probably needs to be freed above.

- NRK



Howdy,


Thanks for the feedback. I'm not a C programmer in any way, shape or 
form so it's completely expected for there to be issues with the code.



I'll do what I can about what you've mentioned and come back for 
feedback or advice if you don't mind.



Thanks,

Yan



OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: [dev] Announcing a couple small X11 utilities

2023-07-29 Thread Yan Doroshenko

Howdy,


I've created a patch for sxot that adds a -m (--monitor) param that 
allows to select which monitor to capture in a multihead setup. Let me 
know what you think.



Regards,

Yan


On 7/4/23 15:51, NRK wrote:

Hi all,

I'd like to share some small X11 utilities that I've developed and have
been using in my daily setup. The utilities are all fairly small in
size and requires only typical X libraries.

sxcs


This is a simple color picker and magnifier. My issue with all other
existing minimal color pickers were that due to no magnification,
picking out specific pixels was fairly difficult.

The usage is simple, you launch the program and pick a color. The result
will be output to stdout in tab separated RGB, HSL and HEX format.

Repo: https://codeberg.org/NRK/sxcs
SLoC: ~628
Dependencies: Xlib, libXcursor

sxot


This one is a *very minimal* screenshot tool. I wrote this when I
realized that other cli screenshot tools (scrot, maim) do way too much.

sxot on the other hand is meant to follow the unix philosophy - it
simply takes a screenshot and outputs a binary ppm image to stdout.
Any other functionalities are supposed to be handled by more specialized
tools. E.g sx4 (see below) for selection, optipng to convert to png,
xclip for copying to clipboard etc.

Repo: https://codeberg.org/NRK/sxot
SLoC: ~251
Dependencies: Xlib, libXfixes

sx4
===

This one is a selection tool. It outputs the selection rectangle to
stdout which can then be used for other purposes, such as screenshoting
or screen-recording a specific area.

Repo: https://codeberg.org/NRK/sx4
SLoC: ~500
Dependencies: Xlib, libXext

---

And that's all. Feel free to report any bugs, send bug-fixes, request
additional features (within the project's scope) etc.

- NRK

diff --git a/sxot.c b/sxot.c
index de87126..712ba66 100644
--- a/sxot.c
+++ b/sxot.c
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 
 typedef uint8_t u8;
 typedef uint32_tu32;
@@ -207,6 +208,7 @@ main(int argc, char *argv[])
 		"usage: sxot [options]\n"
 		"Options:\n"
 		"  -g, --geomCapture the specified rectangle\n"
+		"  -m, --monitor nCapture the specified monitor\n"
 		"  -c, --curosr   Capture the cursor also\n"
 	);
 	Str version = S(
@@ -237,6 +239,20 @@ main(int argc, char *argv[])
 			if (!parse_geom(opt.v, str_from_cstr(argv[++i]))) {
 fatal(S("invalid geometry\n"));
 			}
+
+		} else if (str_eq(arg, S("--monitor")) || str_eq(arg, S("-m"))) {
+			int m[1];
+			str_to_int(str_from_cstr(argv[++i]), m);
+
+			XRRScreenResources *screen;
+			screen = XRRGetScreenResources (x11.dpy, DefaultRootWindow(x11.dpy));
+			XRRCrtcInfo *crtc_info;
+			crtc_info = XRRGetCrtcInfo (x11.dpy, screen, screen->crtcs[m[0]]);
+
+opt.x = crtc_info->x;
+			opt.y = crtc_info->y;
+			opt.h = crtc_info->height;
+			opt.w = crtc_info->width;
 		} else if (str_eq(arg, S("--cursor")) || str_eq(arg, S("-c"))) {
 			opt.capture_cursor = true;
 		} else if (str_eq(arg, S("--help")) || str_eq(arg, S("-h"))) {


OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: [dev] Minimalist software. Should I care?

2023-07-06 Thread Yan Doroshenko

On 7/5/23 16:53, Dave Blanchard wrote:

On Wed, 5 Jul 2023 11:55:59 +0300
Sergey Matveev  wrote:


*** s...@plunder.tech [2023-07-04 19:37]:

I use ST without any patching, and have done so for years.  It is very fast and
works flawlessly in my experience.  All the other terminals have serious issues.

Agreed! I use st for more than 10 years already and completely do not
understand what are people missing from it, except for useless things
that must not be in it (like scrollback support).

Useless things like scrollback support. LOL


No noticeable or any seriously impacting issues I can remember so far.

Other than all of the "useless" missing features of course. And I guess you did 
not run into the multitude of noticeable little compatibility problems with software that 
is designed to expect the behavior of the gold standard, Xterm.


It does everything is
should. I run it with tmux running inside for scrollback, history
searching, multiple cut-n-paste buffers and so on.

Isn't that lovely, needing 15 different software packages set up and running to 
do what ONE well designed piece of software should be able to do by itself?


Thanks suckless community and its developers for their wonderful
software (I use dwm, st, dmenu, tabbed, slock) and inspiration resources
for non-bloated sane software!

Yes, it's so sane that you can't even configure the thing on the command line; you have 
to EDIT THE SOURCE FILE to change any options! And then when you complain that some of 
the options are completely undocumented, be prepared to be assaulted by some egghead who 
will scream at you that "well it CLEARLY says right here on page 573 of the Snorfus 
Obscure Guide to Terminal Interactions if you had only BOTHERED to look for that 
SNAGUWFLL means FooBarusLegolas, FOOL. Obviously you are too much of an IDIOT to use this 
software."

If that's sanity, lock me up in the asylum, please.



Guys, what exactly are you trying to prove? That X is good and Y is bad? 
Well, my dad can fuck up your dad real good.



Regards,

Yan


P. S. If you like software that does all the things at once and does 
them good (according to everyone) I suggest you try macos, maybe you'll 
find out something new about the world and/or yourself.




OpenPGP_signature
Description: OpenPGP digital signature


Re: [dev] Simpler WiFi alternatives

2023-05-12 Thread Yan Doroshenko

Hello everyone,

I'd like to take a moment and thank everyone for an extremely polite, 
respectful and to the point discussion regarding the topic at hand. I 
was immensely pleased to have witnessed such a splendid display of a 
real community spirit as well as an immense level of professionalism. No 
doubt everyone involved is absolutely content with himself as well as 
his actions and would have no doubt conducted the same way were it a 
face to face discussion.


Regards,

Yan



On 5/12/23 22:02, Hiltjo Posthuma wrote:

On Fri, May 12, 2023 at 11:39:43AM -0700, Jeremy wrote:

On 05/12/23 08:27AM, Lee Phillips wrote:

Since the administrators of this list are unable or unwilling to block access 
to this loser, I'm unsubscribing. I don't need this kind of garbage in my 
inbox. I have plenty of other kinds of garbage already.


Lee

[...]

Even if we agreed that Fossy has nothing to contribute here, I believe
they are physically unable to block Mr. Fossy, simply because this kind
of moderation is costly.


Just for your info.  The message was only posted a few hours ago and I was
doing other things this day.

I think most people know whats an effective/good/"acceptable" way to
communicate.

Treat others how you want to be treated (very woke and uncool, I know).



OpenPGP_signature
Description: OpenPGP digital signature


[dev] [dwm] DWM Multihead Missing Cursor

2023-05-01 Thread Yan Doroshenko

Hello,


I have a strange thing going on with the mouse cursor in DWM. When I 
move the cursor to another screen right after DWM starts, the cursor 
just disappears. It comes back if a window is created on that screen.


Does anyone know what might be the cause?


Ways to reproduce on the master version (e81f17d):

1. Start DWM.

2. Enable second monitor (xrandr/arandr).

3. Move the mouse cursor to the second monitor.

4. The cursor is missing.


Thanks,

Yan



OpenPGP_signature
Description: OpenPGP digital signature


[dev] [dwm] dmenu dwm wrong screen

2022-10-28 Thread Yan Doroshenko

Helo,


I have a strange behavior of dmenu inside dwm with two monitors. dmenu 
is displayed on the screen with the mouse cursor (instead of the active 
one) if there are no windows open on any screen. Otherwise it works fine.



Is this expected behavior?


Thanks,

Yan




OpenPGP_signature
Description: OpenPGP digital signature


Re: [dev] [dwm] Incorrect resolution when turning on dual monitors

2022-05-07 Thread Yan Doroshenko

On 07.05.22 18:13, Hiltjo Posthuma wrote:

On Fri, May 06, 2022 at 10:27:32PM -0400, Christopher Brown wrote:

Hello,

I have been intermittently encountering an issue where dwm messes up
my monitor resolutions when powering on my two monitors. Frequently,
both screens will be combined on one monitor while the other monitor
does not receive input. The "Two independent outputs" section of the
multi monitor dwm documentation seems to describe what I am
experiencing. I tried using the xrandr options it mentions, but I will
still sometimes encounter the issue. Does anyone know how to prevent
this from happening?

Thank you,
Christopher


Hi Christopher,

Do you run the latest git version?

Can you try the commit
https://git.suckless.org/dwm/commit/d93ff48803f04f1363bf303af1d7e6ccc5cb8d3f.html
or if you run the git version revert the commit and see if it solves the issue?

Not sure if this is of any help, but I was having troubles with DWM on 
two monitors as well, one screen was not recognized by DWM.


A 1 second delay before running my screen layout script was enough to 
fix it, here's an explanation:


https://wiki.archlinux.org/title/xrandr#Setting_resolution_from_.xinitrc_doesn't_work


Regards,

Yan



OpenPGP_signature
Description: OpenPGP digital signature


[dev] ...

2022-05-02 Thread Yan Doroshenko

On 01.05.22 21:20, NRK wrote:

On Sun, May 01, 2022 at 06:57:33PM +0200, Yan Doroshenko wrote:

(stupid qustion alert)

But how can I try, whether my xrandr in autostart works, if I run version
with no autostart patch?


Hi Yan,

You don't need a patch to execute something at startup. If you're using
startx directly, then look into `xinitrc` (man 1 xinit has some
examples). And if you're using some login/display manager then look into
it's documentation instead.

- NRK

I've added the script to .xprofile and everything seems to work every 
time, while placing it in the autostart of the DWM never works after 
startup/reboot. So it looks like there's an issue with how the 
cool_autostart patch runs the script.


Thanks,

Yan



OpenPGP_signature
Description: OpenPGP digital signature


Re: [dev] [dwm] Multihead Issues Autostart

2022-05-01 Thread Yan Doroshenko

On 01.05.22 15:10, Hiltjo Posthuma wrote:

On Sun, May 01, 2022 at 12:56:50PM +0200, Yan Doroshenko wrote:

Hello,


I'm using DWM on two monitors with cool_autostart patch and in the autostart
array I'm running xrandr to set the monitor layout.

Quite often a situation happens when the second monitor is enabled (arandr
displays it as active and in correct position, feh sets the background on
it), but is unrecognized by DWM (there's no panel on it and windows can not
be moved onto it). Any change in display layout fixes the issue and DWM
recognizes the second screen.


Do you have any ideas as to why it can be happening?


Thanks,

Yan


Can you try the latest git version (without patches)?


(stupid qustion alert)

But how can I try, whether my xrandr in autostart works, if I run 
version with no autostart patch?




OpenPGP_signature
Description: OpenPGP digital signature


[dev] [dwm] Multihead Issues Autostart

2022-05-01 Thread Yan Doroshenko

Hello,


I'm using DWM on two monitors with cool_autostart patch and in the 
autostart array I'm running xrandr to set the monitor layout.


Quite often a situation happens when the second monitor is enabled 
(arandr displays it as active and in correct position, feh sets the 
background on it), but is unrecognized by DWM (there's no panel on it 
and windows can not be moved onto it). Any change in display layout 
fixes the issue and DWM recognizes the second screen.



Do you have any ideas as to why it can be happening?


Thanks,

Yan



OpenPGP_signature
Description: OpenPGP digital signature


Re: [dev] Regarding dwm and st logo being removed

2022-04-28 Thread Yan Doroshenko

On 28.04.22 12:19, Laslo Hunhold wrote:

On Thu, 28 Apr 2022 08:34:36 +0600
NRK  wrote:

Dear NRK,


Recently noticed that the dwm and st logo was removed from their
homepages[0][1].

I was wondering if there's any specific reason for that, or if there's
plan for a new logo(s)?

I atleast really liked the current logos, as they reflect the
simiplicity of the software quite nicely :)

[0]: https://dwm.suckless.org
[1]: https://st.suckless.org

I made the logos a few years ago and Hiltjo removed them recently. I
also liked them very much and would like to see them included again, but
respect that it's his discretion to remove them as he is the maintainer.

What do the others think?

With best regards

Laslo



Hey guys,

Just my two cents - I liked the logos and never use dark mode.

Regards,

Yan



OpenPGP_signature
Description: OpenPGP digital signature