Drawing a line on screen

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
MochiMoppel
Posts: 1103
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 352 times

Drawing a line on screen

Post by MochiMoppel »

This may be the craziest code I've ever written.
The challenge: Place a thin, moveable line on the screen. Use as simple and little code as possible.

Such a line was requested here and I can see the usefulness when superimposed on line charts. I occasionally could use them myself for easier alignment of windows.

What we need for a horizontal line is a window with a colored background, no text, no decoration, 1px high and as wide as the screen.
First idea: urxvt window. Colored background OK, 1px height may be tricky but possible, but unfortunately the borderLess argument is buggy and doesn't work.

Second idea:Yad window. Would not work. Yad's WM_NORMAL_HINTS directive specifies a minimum height of 15px.

Third idea: Gtkdialog window. Bingo!
An orthodox solution would create a temporary file with a SVG line and then load this file into gtkdialog as <pixmap>. Not a big deal, but it requires a tmp file, and I just don't like tmp files.

So here comes the crazy part. This code creates a gtkdialog window with a <text> widget. The text uses pango markup and has a colored background. The text itself contains of only 2 spaces - with an insane amount of letter_spacing, which stretches the text background to roughly 9000px, Now that we have enough width to fill a cinema screen we need to decrease the height to 1px. This is done by decreasing the font size to the lowest possible value. The lowest value is zero, and this even works, but it removes the background (and its color) and leaves a thin 1px gray line (not so bad if we need a gray line :D ). For a color line the minimum is 1. Font sizes are not measured in pixel and a font size of 1 is not guaranteed to result in a 1px line (in my case it does, but tested in other distros it resulted in a 3px line), but it's still a fairly thin line.

Using busybox ash to increase speed and fun:

Code: Select all

#!/bin/ash
linecolor=red
thickness=1
echo '<window title="'$linecolor'" decorated="false" resizable="false" margin="0" tooltip-text="'$linecolor' line">
<text use-markup="true"><label>"<span letter_spacing='\''9999999'\'' bgcolor='\'$linecolor\'' font='\'$thickness\''>  </span>"</label></text>
</window>'| gtkdialog -cs

linecolor can be any valid X11 color name (e.g. red, lavender or PeachPuff ) or a hex triplet (e.g. #A52A2A). In case of invalid value the line defaults to black.

Focussing and subsequentially moving/deleting such a line can be tricky. Two feature can help:
1) The window appears in the taskbar with its color name. Right clicking on the taskbar tab allows to minimize, move and close the window. Here it is also possible to set the layer to "Above" which will keep the line on top of other windows.
2) The window has a tooltip. When the mouse cursor hovers over the line and the tooltip appears it means that a left click will focus the window. The easiest way to move the line: Press Alt key and keep it pressed, then slowly position the mouse and find the "sweet spot" that triggers the tooltip. When the tooltip appears, press the left mouse button and drag the line to the desired position.

Shortcomings: Above code works only for horizontal lines. For vertical lines we would need the SVG <pixmap> approach, which also would allow to set the line height to a precise value in pixel.

Have fun!

[ EDIT ]────────────────────────────────────────────────────────────────
Above code places the line always at the center. Normally that requires a subsequent move to the intended position.
It might be more useful to create the line where you click on the screen.
Change
gtkdialog -cs
to
gtkdialog -sG +0+$(sleep .5; xwininfo > /dev/null; getcurpos | cut -d' ' -f2) &
The script will start with a cross-hair cursor. Position the cursor to the intended line position and click.

Last edited by MochiMoppel on Sun Jan 08, 2023 12:01 pm, edited 2 times in total.
User avatar
rockedge
Site Admin
Posts: 5681
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 1954 times
Been thanked: 2080 times
Contact:

Re: Drawing a line on screen

Post by rockedge »

@MochiMoppel That is pretty cool code. Works great in F96 and I will put the script into KLV perhaps as a handy screen tool since its just a few bytes added in.

step
Posts: 510
Joined: Thu Aug 13, 2020 9:55 am
Has thanked: 50 times
Been thanked: 179 times
Contact:

Re: Drawing a line on screen

Post by step »

Thanks. Another option to try is pango-view, a little known command of the pango package. I have just tried your markup in Fatdog64 to create a vertical like with this

Code: Select all

pango-view --markup --rotate=90 -t '<span letter_spacing="9999999" bgcolor="red" font="1">   </span>'

and it works with two big drawbacks: the window is decorated, and the background is white. So, it isn't good enough to meet the goal. However, pango-view has a "make background transparent" option, --background=transparent, although it didn't work when I tried it (maybe my fault?). Still, there is no direct way to undecorate the window, like gtkdialog and yad can do.

pango-view --help wrote:

Usage:
pango-view [OPTION…] - FILE

Help Options:
-h, --help Show help options
--help-all Show all help options
--help-cairo Options understood by the cairo backend

Application Options:
--no-auto-dir No layout direction according to contents
--backend=cairo/xft/ft2 Pango backend to use for rendering (default: cairo)
--background=red/#rrggbb/#rrggbbaa/transparent Set the background color
-q, --no-display Do not display (just write to file or whatever)
--dpi=number Set the resolution
--align=left/center/right Text alignment
--ellipsize=start/middle/end Ellipsization mode
--font=description Set the font description
--foreground=red/#rrggbb/#rrggbbaa Set the text color
--gravity=south/east/north/west/auto Base gravity: glyph rotation
--gravity-hint=natural/strong/line Gravity hint
--header Display the options in the output
--height=+points/-numlines Height in points (positive) or number of lines (negative) for ellipsizing
--hinting=none/auto/full Hinting style
--indent=points Width in points to indent paragraphs
--justify Align paragraph lines to be justified
--language=en_US/etc Language to use for font selection
--margin=CSS-style numbers in pixels Set the margin on the output in pixels
--markup Interpret text as Pango markup
-o, --output=file Save rendered image to output file
--pixels Use pixel units instead of points (sets dpi to 72)
--rtl Set base direction to right-to-left
--rotate=degrees Angle at which to rotate results
-n, --runs=integer Run Pango layout engine this many times
--single-par Enable single-paragraph mode
-t, --text=string Text to display (instead of a file)
--version Show version numbers
--waterfall Create a waterfall display
-w, --width=points Width in points to which to wrap lines or ellipsize
--wrap=word/char/word-char Text wrapping mode (needs a width to be set)

User avatar
MochiMoppel
Posts: 1103
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 352 times

Re: Drawing a line on screen

Post by MochiMoppel »

@step I tried pango-view before. The real show stopper is its inability to close normally. The window has to be killed. When running from a console window it's easy to accidentally confirm a left-over "Kill this window?" message, thus killing the X server instead. Happened to me more than once :shock:

Apart from that, pango-view could be a hot contender for the simplest line script. A vertical line could be produced like this - without any pango markup!

Code: Select all

pango-view --height=99999 --margin=1 --background=red -t ''

it works with two big drawbacks: the window is decorated, and the background is white. So, it isn't good enough to meet the goal.

The background problem is solved, as you can see.
The decoration problem remains

Still, there is no direct way to undecorate the window, like gtkdialog and yad can do

Even worse: There seems to be no indirect way either. pango-view doesn't send a WM_CLASS instruction to the file manager, so in JWM it's not possible to open the window with a "noborder" <group> option

But not everything is bad:
- Horizontal and vertical lines are possible
- When starting with a fat line (fill the empty text string with some spaces), the line thickness can be manually adjusted, down to 1px. Not (easily) possible with gtkdialog.

xx_T3n0ch_X
Posts: 36
Joined: Thu Jul 22, 2021 1:31 am
Has thanked: 3 times
Been thanked: 10 times

Re: Drawing a line on screen

Post by xx_T3n0ch_X »

This is something I need. I'm about to do data entry, the sources are low quality document scans of tables without borders and with very disperse columns. It is difficult and time consuming to discern if you are looking at the correct line of text on both ends of the page, a screen wide cross-hair would be perfect for this task. Anyways, looking forward to see how this develops.

User avatar
MochiMoppel
Posts: 1103
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 352 times

Drawing a line on screen

Post by MochiMoppel »

I've edited my initial post so that the line position can be set with a mouseclick. Below script also uses this method.

Thin red vertical hairline
Who said that a vertical line is not possible with <text>?

Code: Select all

#!/bin/ash
echo '<window title="red" decorated="false" resizable="false" margin="0" tooltip-text="red line">
<text use-markup="true"><label>"<span bgcolor='\'red\'' font='\'2\''>'"$(yes \ |head -n500)"'</span>"</label></text>
</window>'| gtkdialog -sG +$(sleep .5; xwininfo > /dev/null; getcurpos | cut -d' ' -f1)+0  1>/dev/null & 

In my tests a minimum fontsize of 2 reduced the width of an ASCII space to 1px. Stacking 500 of such spaces would create a vertical line, more than high enough to fill my 1600px screen height.


xx_T3n0ch_X wrote: Fri Jan 06, 2023 3:54 pm

This is something I need. I'm about to do data entry, the sources are low quality document scans of tables without borders and with very disperse columns. It is difficult and time consuming to discern if you are looking at the correct line of text on both ends of the page, a screen wide cross-hair would be perfect for this task.

I'm afraid "a screen wide cross-hair" (= a combination of a horizontal and a vertical line, movable as a unit) is out of the question with any of these methods, but do you really need a script or program?
If you need a horizontal guideline for wide, hard to read data tables why not do what many people in my office do when they have to input data from paper sources: They take a bamboo ruler and place it under the line they have to read, then slide the ruler downwards as they progress. Low tech but efficient,
IMO the best substitute for a bamboo ruler would be a "shaded" window. Just take any window, set it to "Shade" and "Layer:Above", resize it to screen width and you have a ~22px high "ruler". The big advantage is the easy operation. Can be dragged with the left mouse button and doesn't need the Alt key and it provides the window menu with a right click.

User avatar
Sofiya
Posts: 1786
Joined: Tue Dec 07, 2021 9:49 pm
Has thanked: 1192 times
Been thanked: 1058 times

Re: Drawing a line on screen

Post by Sofiya »

These are cool features.
Thank you

Attachments
Снимок экрана_2023-01-08_12-13-42.png
Снимок экрана_2023-01-08_12-13-42.png (155.68 KiB) Viewed 1691 times

Vanilla Dpup 9.2.X - KLV-Airedale - KLA-OT2
PUPPY LINUX Simple fast free

don570
Posts: 623
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 98 times

Re: Drawing a line on screen

Post by don570 »

This is a different topic but programmers should know that a script can create a SVG image file.
Gtkdialog can then load that image.
Here's an example...

Code: Select all

#!/bin/bash

echo ' <svg version="1.1" width="150" height="150" id="svg1">
    id="svg1854"
  
  <defs
     id="defs1856" />
     id="base" />
  <g
     id="g863"
     transform="matrix(2.548887,0.000000,0.000000,2.401153,-1219.592,-402.1428)"
     style="font-size:12;">
    <path
       fill="#333333"
       d="M516.791,176.799l-3.211,6.996c6.373,1.846,11.049,7.724,11.049,14.683    c0,8.435-6.861,15.296-15.294,15.296c-7.314,0-13.438-5.163-14.938-12.034l-7.119,3c2.729,9.624,11.559,16.682,22.057,16.682    c12.669,0,22.942-10.272,22.942-22.944C532.277,188.421,525.797,179.897,516.791,176.799z"
       id="path865" />
    <g
       id="g867">
      <path
         fill="#333333"
         d="M515.889,206.126c-0.555,0-1.111-0.211-1.539-0.633l-7.075-7.015h-16.514     c-1.207,0-2.185-0.978-2.185-2.185c0-1.207,0.978-2.185,2.185-2.185h18.313l8.354,8.281c0.857,0.85,0.863,2.233,0.014,3.091     C517.014,205.911,516.451,206.126,515.889,206.126L515.889,206.126z"
         id="path869" />
    </g>
  </g>
</svg>
' >  /root/baconrecorder.svg

I believe I used inkscape to get the code or else downloaded it from a google chrome site.

Another example:
here is graph paper that was created
https://oldforum.puppylinux.com/viewtopic.php?t=90727

User avatar
MochiMoppel
Posts: 1103
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 352 times

Drawing cross-hairs on screen

Post by MochiMoppel »

@Sofiya Thank you for testing. Screenshot is taken from Vanilla Dpup? I'm starting to dislike the fact that the horizontal line can't be thinner than 3px. Well, it can, but this would require to use a gtkdialog version compatible with GTK2. In FP96 such version exists ( /usr/sbin/gtk2dialog) but I don't know how common this is.

I have a better (?) idea. Still weird yet not as weird as the first one. Inspired by @xx_T3n0ch_X and his/her request for "a screen wide cross-hair" and my stupid remark that this would not be possible I did just that.

Simple and elegant cross-hair lines

Code: Select all

#!/bin/ash
pkill -f lines_ontop_nofocus && exit
set  $(xwininfo > /dev/null ; getcurpos)
echo '<window title="h-line" decorated="false" margin="0"  width-request="2000"><hseparator></hseparator></window>'| gtkdialog --class lines_ontop_nofocus -sG +0+$2 &
echo '<window title="v-line" decorated="false" margin="0" height-request="2000"><vseparator></vseparator></window>'| gtkdialog --class lines_ontop_nofocus -sG +$1+0 &
separatorlines.png
separatorlines.png (43.15 KiB) Viewed 1589 times

The script uses gtkdialog with a widget separator as its only content.

Pros:
- Seems to work in all Puppies
- Simple code
- 2 pairs of cross-hairs possible (requires a keyboard shortcut for the script)
- Easy to generate and delete: Script acts as toggle. First run creates lines, next run deletes them.
- Stays on top of other windows and does not steal focus (requires appropriate settings in JWM)
- Lines consist of 2 colors, which makes them suitable for dark and light backgrounds alike

Cons:
- No choice of colors
- Line thickness 2px. A 1px thickness would require a GTK2 compatible gtkdialog

Technical notes
The class name lines_ontop_nofocus takes advantage of gtkdialog's (undocumented?) --class option and the fact, that in @rockedge 's FP96 a JWM group for all windows with class name "ontop" is defined in /root/.jwmrc. This means that in FP96 the cross-hair lines will try to stay on top of other windows. Though FP96 settings are a clever idea, they are incomplete. I therefore recommend to add generic Class/Name group settings to the file /root/.jwm/jwmrc-personal . When done run jwm -restart:

Code: Select all

<Group><Class>ontop|above</Class><Option>layer:above</Option></Group>
<Group><Name>ontop|above</Name><Option>layer:above</Option></Group>

<Group><Class>nofocus</Class><Option>nofocus</Option></Group>
<Group><Name>nofocus</Name><Option>nofocus</Option></Group>

<Group><Class>notitle</Class><Option>notitle</Option></Group>
<Group><Name>notitle</Name><Option>notitle</Option></Group>

<Group><Class>noborder</Class><Option>noborder</Option></Group>
<Group><Name>noborder</Name><Option>noborder</Option></Group>

For the cross-hairs only the first 2 blocks are relevant
The remaining notitle and noborder are very useful for opening any application without window decoration even when the application doesn't provide an option to do so. Many more options are possible, but that would be a completely different topic.

User avatar
Keef
Posts: 249
Joined: Tue Dec 03, 2019 8:05 pm
Has thanked: 3 times
Been thanked: 66 times

Re: Drawing a line on screen

Post by Keef »

Just tried this on Fatdog with Openbox, and it works perfectly.

User avatar
JakeSFR
Posts: 252
Joined: Wed Jul 15, 2020 2:23 pm
Been thanked: 123 times

Re: Drawing a line on screen

Post by JakeSFR »

MochiMoppel wrote:

gtkdialog's (undocumented?) --class option

It's documented under gtkdialog --help-all.

Btw, you can achieve the ontop, nofocus and notitle with <window type-hint="6" ...> (6 = GDK_WINDOW_TYPE_HINT_DOCK).
EDIT: For JWM you apparently also need skip-taskbar-hint="true".

Greetings!

[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
User avatar
Sofiya
Posts: 1786
Joined: Tue Dec 07, 2021 9:49 pm
Has thanked: 1192 times
Been thanked: 1058 times

Re: Drawing cross-hairs on screen

Post by Sofiya »

MochiMoppel wrote: Sun Jan 15, 2023 8:16 am

@Sofiya Thank you for testing. Screenshot is taken from Vanilla Dpup? I'm starting to dislike the fact that the horizontal line can't be thinner than 3px. Well, it can, but this would require to use a gtkdialog version compatible with GTK2. In FP96 such version exists ( /usr/sbin/gtk2dialog) but I don't know how common this is.

@Sofiya Thank you for testing. Screenshot is taken from Vanilla Dpup?

Taken from KLV-Airedale

it's just gorgeous!!! :thumbup2: :thumbup2: :thumbup2:

Attachments
gtk2dialog.false.gz
put in /usr/sbin/
(266.19 KiB) Downloaded 27 times
Screenshot.jpg
Screenshot.jpg (11.07 KiB) Viewed 1672 times

Vanilla Dpup 9.2.X - KLV-Airedale - KLA-OT2
PUPPY LINUX Simple fast free

User avatar
MochiMoppel
Posts: 1103
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 352 times

Re: Drawing a line on screen

Post by MochiMoppel »

JakeSFR wrote: Sun Jan 15, 2023 2:24 pm

Btw, you can achieve the ontop, nofocus and notitle with <window type-hint="6" ...>

Sure, but the problem is that _NET_WM_WINDOW_TYPE_DOCK also implies nomove and noresize, therefore makes it unsuitable for our purpose. The user should be able to move the lines. None of the 14 window types provide the feature set that is needed for the lines. To make matters worse: What exactly the feature set comprises depends on the WM, and even within JWM the feature set may change from version to version (e.g. did change for _NET_WM_WINDOW_TYPE_NOTIFICATION).

EDIT: For JWM you apparently also need skip-taskbar-hint="true".

Apparently not ;)
I don't want to skip anything. Assessing and operating the hair lines from the tray/taskbar is essential. Moving is much easier and (temporarily) hiding a line is just a click on the window tab in the tray (to minimize the window). Almost impossible without a "taskbar-hint".

@Sofiya Glad you like it, but ... :o :o :o what does the screenshot show? The lines are supposed to be 2px and 2-tone (shaded). Yours are 3px and monotone black. Maximized you could use them as a poor-man's screensaver :lol:

User avatar
Sofiya
Posts: 1786
Joined: Tue Dec 07, 2021 9:49 pm
Has thanked: 1192 times
Been thanked: 1058 times

Re: Drawing a line on screen

Post by Sofiya »

MochiMoppel wrote: Mon Jan 16, 2023 11:58 am

@Sofiya Glad you like it, but ... :o :o :o what does the screenshot show? The lines are supposed to be 2px and 2-tone (shaded). Yours are 3px and monotone black. Maximized you could use them as a poor-man's screensaver :lol:

So intended :D
in the original on KLV-Airedale I have it like this ;)

Attachments
Screenshot.jpg
Screenshot.jpg (34.53 KiB) Viewed 1611 times

Vanilla Dpup 9.2.X - KLV-Airedale - KLA-OT2
PUPPY LINUX Simple fast free

User avatar
MochiMoppel
Posts: 1103
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 352 times

Re: Drawing a line on screen

Post by MochiMoppel »

@Sofiya Still I don't understand what you used. Looks like you used the initial script, not the last one. AFAIK it would not be possible to remove the shading from a separator line.

User avatar
Sofiya
Posts: 1786
Joined: Tue Dec 07, 2021 9:49 pm
Has thanked: 1192 times
Been thanked: 1058 times

Re: Drawing a line on screen

Post by Sofiya »

MochiMoppel wrote: Mon Jan 16, 2023 12:33 pm

@Sofiya Still I don't understand what you used. Looks like you used the initial script, not the last one. AFAIK it would not be possible to remove the shading from a separator line.

here is what i use https://forum.puppylinux.com/viewtopic. ... 600#p78600
nothing is impossible :geek:

Vanilla Dpup 9.2.X - KLV-Airedale - KLA-OT2
PUPPY LINUX Simple fast free

User avatar
MochiMoppel
Posts: 1103
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 352 times

Re: Drawing a line on screen

Post by MochiMoppel »

MochiMoppel wrote: Mon Jan 16, 2023 11:58 am

I don't want to skip anything. Assessing and operating the hair lines from the tray/taskbar is essential. Moving is much easier and (temporarily) hiding a line is just a click on the window tab in the tray (to minimize the window). Almost impossible without a "taskbar-hint".

@JakeSFR I now played with Fatdog and noticed that with Openbox as window manager there is no way to move a window from the taskbar. Would explain your lack of interest in "taskbar-hints" but makes me wonder why @Keef found that is "works perfectly" with Openbox. Do I miss something?

User avatar
Keef
Posts: 249
Joined: Tue Dec 03, 2019 8:05 pm
Has thanked: 3 times
Been thanked: 66 times

Re: Drawing a line on screen

Post by Keef »

MochiMoppel

Looks like gave enthusiastic, but ultimately unhelpful feedback. I hadn't realised about the 'move' ability in JWM, and was quite 'happily' chasing the lines with the mouse cursor. Now I've tried it on JWM, my needs have changed.
I found this: https://lecorbeausvault.wordpress.com/2 ... bindings/
EDIT - this link is more helpful: https://github.com/I-LeCorbeau/dotfiles/wiki/Move
Adding the code as described in the rc.xml file, means that after I grab focus for the 'window' from the taskbar, I can move the line around by using Alt + arrow keys.

User avatar
MochiMoppel
Posts: 1103
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 352 times

Re: Drawing a line on screen

Post by MochiMoppel »

At last: "orthodox" solution using 1px SVG lines
As already indicated in the initial post using image files for the lines would be the way to go when precision is required.
Lines can be deleted by running the code a second time.

Code: Select all

#!/bin/ash
thickness=1
linecolor=red

wclass=lines_ontop_nofocus
busybox pkill -f $wclass && { Xdialog -y "Existing lines removed\nCreate new ones?" x ||  exit ;}
htmp=/tmp/hscreenline.svg
vtmp=/tmp/vscreenline.svg
trap "sleep 1;rm  $htmp $vtmp 2>/dev/null" EXIT

set -- $(xprop > /dev/null ; getcurpos)
echo \<"svg><rect width='2000' height='$thickness' fill='$linecolor'/></svg>" > $htmp
echo \<"svg><rect width='$thickness' height='2000' fill='$linecolor'/></svg>" > $vtmp
echo '<window title="hline" decorated="false" focus-on-map="false" margin="0"><pixmap><input file>"'$htmp'"</input></pixmap></window>' | gtkdialog --class $wclass -sG +0+$2 &
echo '<window title="vline" decorated="false" focus-on-map="false" margin="0"><pixmap><input file>"'$vtmp'"</input></pixmap></window>' | gtkdialog --class $wclass -sG +$1+0 &

Where to go from here?
So far all codes are very basic ... probably not awfully useful. I'm now thinking of integrating lines into a measurement tool similar to pxRuler. Let's see how this works out.

User avatar
MochiMoppel
Posts: 1103
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 352 times

Re: Drawing a line on screen

Post by MochiMoppel »

Finally: ScreenLiner, the line pizza with everything

To bring all this crazy stuff to an end I created a little script that places multiple lines on screen

  • in any available color and thickness
  • multiple undo levels
  • real-time length display, so it can be used as a measuring tool.
  • ultra 'portable' - it saves all line options to itself (therefore script needs write permission)

To "install": Decompress attached script and make it executable.

screenliner.gz
(2.19 KiB) Downloaded 40 times
screenliner.jpg
screenliner.jpg (37.28 KiB) Viewed 1098 times
Last edited by MochiMoppel on Tue Dec 26, 2023 9:22 am, edited 2 times in total.
User avatar
greengeek
Posts: 1200
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 338 times
Been thanked: 145 times

Re: Drawing a line on screen

Post by greengeek »

MochiMoppel wrote: Thu Dec 21, 2023 1:51 am

...

  • real-time length display, so it can be used as a measuring tool.
    If requested and people find it useful I can move it to the Software forum - not really sure where it fits.

Brilliant! A little beauty. Even if used for no other reason than as a measuring tool this is brilliant.
(In fact this may make pxruler redundant - which is a little bit sad actually)
Lots of other potential uses too though.
Seems to work perfectly on Fossa64 9.5Mid from Ozsouth. (Quite a minimal pup)

User avatar
Keef
Posts: 249
Joined: Tue Dec 03, 2019 8:05 pm
Has thanked: 3 times
Been thanked: 66 times

Re: Drawing a line on screen

Post by Keef »

Very good, like this a lot.
Minor typo 'lenght', but apart from that, no complaints at all.

User avatar
mikewalsh
Moderator
Posts: 5546
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 564 times
Been thanked: 1670 times

Re: Drawing a line on screen

Post by mikewalsh »

Thank YOU, Mochi. Best Xmas prezzie ever!

As a graphic design afficionado, I'm already visualizing a ton of uses I could put this to. Seems to run absolutely everywhere, as well; haven't yet found a Pup it won't run in....

Cheers, mate. Nice one! :thumbup:

Mike. :)

Puppy "stuff" ~ MORE Puppy "stuff" ~ ....and MORE! :D
_______________________________________________________

Image

User avatar
bugnaw333
Posts: 227
Joined: Wed Jul 20, 2022 11:04 pm
Location: Cebu, Philippines
Has thanked: 338 times
Been thanked: 32 times

Re: Drawing a line on screen

Post by bugnaw333 »

Nice! :thumbup2: Thank you Mochi !

Attachments
line.png
line.png (397.57 KiB) Viewed 977 times
User avatar
MochiMoppel
Posts: 1103
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 352 times

Re: Drawing a line on screen

Post by MochiMoppel »

mikewalsh wrote: Thu Dec 21, 2023 2:24 pm

haven't yet found a Pup it won't run in....

Try Puppy 4.2 :mrgreen:

BTW: ScreenLiner - with some improvements by @radky - is now included in Bookworm Pup64 10.0.4.
OOTB located in the "Personal" menu category, but this can easily be changed using the also included Menu manager.

Trapster
Posts: 139
Joined: Sat Aug 01, 2020 7:44 pm
Has thanked: 1 time
Been thanked: 37 times

Re: Drawing a line on screen

Post by Trapster »

Does not work 4.10 :( :mrgreen:

Code: Select all

root@linux_server:~$ # cat /etc/puppyversion
410
root@linux_server:~$ # screenliner

(gtkdialog:19601): Gtk-WARNING **: Failed to set text from markup due to error parsing markup: Attribute 'fgcolor' is not allowed on the <span> tag on line 1 char 49

(gtkdialog:19601): Gtk-WARNING **: Failed to set text from markup due to error parsing markup: Attribute 'fgcolor' is not allowed on the <span> tag on line 1 char 49
sh: xprop: command not found
sh: getcurpos: command not found
sh: xprop: command not found
pkill: applet not found
don570
Posts: 623
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 98 times

GTKDIALOG -red line in window

Post by don570 »

This is different topic but I show how to place a red line in a GTKDIALOG window
using an svg image
viewtopic.php?t=10207

screenshot-red_line.png
screenshot-red_line.png (8.65 KiB) Viewed 709 times

User avatar
MochiMoppel
Posts: 1103
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 352 times

Re: Drawing a line on screen

Post by MochiMoppel »

Trapster wrote: Fri Dec 29, 2023 2:24 pm

Does not work 4.10 :( :mrgreen:

Surprised? :lol:
This is only the beginning. Many more obstacles, A nice challenge, but with the limitations of gtkdialog3 and without getcurpos it sucks. I gave up. :cry:

On the bright side: In Slacko 5.6 everthing runs OOTB

Lucid 5.2.8 chokes on my brutally short SVG file. Works fine when changing
echo '<'"svg><rect width='$WIDTH' height='$HEIGHT' fill='$vCOLORPICK'/></svg>" > $htmp
to
echo '<'"svg width='$WIDTH' height='$HEIGHT'><rect width='$WIDTH' height='$HEIGHT' fill='$vCOLORPICK'/></svg>" > $htmp

User avatar
MochiMoppel
Posts: 1103
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 352 times

Re: Drawing a line on screen

Post by MochiMoppel »

Not a joke anymore: Lines for Puppy 4.x

Looking back at the original post, this was the challenge:
"What we need for a horizontal line is a window with a colored background, no text, no decoration, 1px high and as wide as the screen."

We now know what does not work: urxvt, yad and @step 's idea of pango-view.
What we haven't looked at is /usr/X11/bin/yaf-splash, a binary (!) tool that existed in the earliest Puppies up to pre-Woof-CE Puppies like Lucid 5.2.8 and Slacko 5.6. Creating a centered 1px red line in those early Puppies is possible with the command /usr/X11/bin/yaf-splash -bw 0 -bg red -geometry 9999x1. In fact with a more precise geometry setting the line can take any color and any width, length and position on screen. Can't get any simpler than that.

yaf-splash is a no-nonsense dialog tool which can perform tricks none of the usual suspects gtkdialog/yad/gxmessage/Xdialog is capable of.
Unfortunately it was removed when the /usr/X11 directory was removed. But it's not dead. AFAIK @BarryK has compiled it for EasyOS, and I have compiled it for BW64. With a little tweaking it works beautifully with TTF fonts.

The following script uses a Xdialog/yaf-splash combo. Tested in Slacko 5.6 and Lucid 5.2.8. An earlier version had a 3rd entry field for the coordinates. This wouldn't require getcurpos and therefore would make it work even in Puppy 4.x

Code: Select all

#! /bin/sh
thickness=3
linecolor=red
while : ;do
set -- $(Xdialog --ok-label Draw --separate-output --left --check "Vertical line" --stdout --2inputsbox "Draw line on screen\n\nTo remove a line: click on line\nTo remove all lines: set Thickness to 0" 0 0 "Thickness (in pixel)" "$thickness" "Color" "$linecolor")
[ $? = 0 ] ||  exit
[ $3 ] &&  thickness=$1 linecolor=$2 || exit
[ $1 = 0 ] && { killall yaf-splash ; thickness=3 ; continue ;}
CURPOS=$(xwininfo > /dev/null; getcurpos)
[ $3 = unchecked ] && W=9999 H=$thickness PLACEMENT="+0+${CURPOS#* }" || W=$thickness H=9999 PLACEMENT="+${CURPOS% *}+0"
/usr/X11/bin/yaf-splash -bw 0 -bg "$linecolor" -geometry ${W}x${H}${PLACEMENT} -text "" &
done
yaf-liner.png
yaf-liner.png (18.87 KiB) Viewed 258 times
Post Reply

Return to “Programming”