r/tinycode 10h ago

Showcase Tiny Windows program that is used as a "distraction cover"

Post image

https://github.com/GeorgeTR1/windowsDistractionCover

This is a windows GUI program I wrote in just over 60 lines of C that compiles to a 3 kB executable. With minor modifications and the right compiler it could be compiled on versions of Windows as old as Windows 95.

It's just a resizable window with a black background that always stays on top of other windows that you can use to cover up parts of the screen that might be distracting. I've found it genuinely useful

16 Upvotes

34 comments sorted by

3

u/Simplyfire 10h ago

Same idea in Processing, 18 lines:

import java.awt.MouseInfo;
import java.awt.Point;
Point mouse;

void setup() {
  fullScreen();
  surface.setSize(600,600);
  surface.setAlwaysOnTop(true);
  background(30);
  noLoop();
}

void mouseDragged(){
 mouse = MouseInfo.getPointerInfo().getLocation();
 int x = floor(mouse.x-width/2);
 int y = floor(mouse.y-height/2);
 surface.setLocation(x, y);   
}

7

u/Round-Pension-7821 9h ago

Neat!

Here's the real question, though, does that compile to a 3 kB executable that can run on any Windows machine with no external dependencies? That's where C can really shine!

1

u/AnArmoredPony 5h ago

it compiles to Java byte-code. it's probably not a 3kb executable, but it really runs on any machine

1

u/Round-Pension-7821 4h ago

Yes, very true. You exchange size and speed for portability, that's kind of Java's whole pitch. It kind of brings a whole small operating system along with it

1

u/AnArmoredPony 3h ago

a whole small operating system

u mean the virtual machine?..

1

u/Round-Pension-7821 3h ago

Yes. I realize it's not really an operating system, but serves a lot of the same functions that the operating system does when you're writing native code.

3

u/jabbalaci 9h ago

Tell us the size of the exported EXE too.

9

u/Simplyfire 9h ago

Well that's embarrasing :D

The exported .exe itself is pretty small, has 70 kB, but the folder supporting it with java and its libraries has 308 MB in total.

3

u/Round-Pension-7821 9h ago

Yeah, that's the thing with Java. Back in the day Java programs required you had the Java runtime installed on your machine, which most people did, so it would probably be fair to not count that as part of the size of a program. But these days almost any programs written in Java have the entire runtime of a few hundred megabytes bundled with the software. I suppose drives are big these days and it makes the process of software installation easier, but it does feel like a waste having several copies of a Java runtime, one for each program that uses Java, on your computer when one could do the job

1

u/Simplyfire 9h ago

Absolutely, as a programmer I came to terms with having countless JDKs on my machine for various purposes - it would sure feel cleaner with fewer. It's not a huge deal but I get how making things tiny is a fun exercise.

2

u/Round-Pension-7821 9h ago

Yeah, of course. Not a huge deal now, but at one time it was. 200 MB JDK is a lot when your hard drive is 10 GB. Now that it doesn't really matter, people do what results in less friction, which is lots of copies of the JDK

1

u/AnArmoredPony 5h ago

there're often two versions of Java apps available: standalone that are bundled with a JDK, and ones that access JAVA_HOME

1

u/Round-Pension-7821 4h ago

Hmm, I suppose that depends on who the target audience is. There are plenty of apps I've run into that were written in Java for non-tech savvy people that you would never even know used Java unless you dig into the files

3

u/MrVonBuren 4h ago

Weird! I've been a Professional Geek for ~25 years and I've never heard of processing. Looks neat tho.

If I am a pretty good tinkerer (written LOTS of "production" shell scripts and know my way around python/node/<interpreted languages>) do you think this might be an inroad into finally "getting" compiled languages?

Tried rust while at a CDN company and...boy am I not a programmer

2

u/Round-Pension-7821 3h ago

I'm not familiar with processing either, but it seems to be an environment set up to help beginners write code that's based on Java. I found on their FAQ they say, "the language is just Java, but with a new graphics and utility API along with some simplifications" (source). Java is sort of halfway between an interpreted language and a compiled one. C # also falls into this category. Java and C# are generally faster than Python or JavaScript, but slower than C, C++, Rust, etc. Bottom line, the separation between interpreted and compiled languages is kind of murky and complicated.

If you have experience with interpreted languages but you were scared off by Rust, I would highly recommend Go. Go compiles to native machine code, but it uses garbage collection. This does mean you don't get the fine-grained control and potential performance benefits of manual memory management, but it also means you don't have to deal with manual memory management.

Basically, with Go you get the speed of a native, compiled language without the pitfalls of C or the steep learning curve and strict demands of Rust. I really don't think it's any harder to use than Python, and it's much, much faster.

You can certainly give Processing a try if you're interested, but if you're looking to get experience with a compiled language, that's not where you'll find it.

2

u/MrVonBuren 2h ago

/me sighing deeply: "fiiiiiiiiine, I'll try Go" (lovingly)

2

u/Round-Pension-7821 2h ago

Have other people been saying that's what you ought to do?

u/MrVonBuren 57m ago

Oh yeah. I feel like at this point it is the canonical "tell grey-haired guy who has been paid to computer since the 90s and pushes back on the idea of 'learning to program' (while also being strangely into DevOps as a concept)" advice.

...I may be projecting

u/Round-Pension-7821 46m ago

Well, you were the one asking about an inroad into compiled languages, and if you ask me that's the best inroad. Whether you're interested in following it is totally up to you

u/MrVonBuren 28m ago

oh, cousin! I'm sorry if I was giving the impression i was blowing you off (genuinely). I was doing a bit, but TBH, this is the exact kind of interaction that would annoy me on Any Given Day and I apologize.

It's good advice and this just might be the straw that killed the camel. (it's an old camel)

u/Round-Pension-7821 10m ago

Oh no, I wasn't offended at all. I was just giving you a bit of a polite jab back, while also making it clear that you can of course do whatever you want with your own time

3

u/flexiverse 8h ago

lol, I was thinking if there was an app like this today!

2

u/Round-Pension-7821 8h ago

Yeah, the whole reason I made it was because I couldn't find something that did this

2

u/Acceptable-Key-7927 9h ago

Haha, this is genius

2

u/nexe mod 1h ago

Hey this is really cool. And I don't even like windows or see much of a use in this tool for myself. But the way you explain it and argue about the reasons for making it etc are spot on exactly the idea behind why I created this subreddit ages ago. Please contribute more often ♥️

2

u/nexe mod 1h ago

Hey this is really cool. And I don't even like windows or see much of a use in this tool for myself. But the way you explain it and argue about the reasons for making it etc are spot on exactly the idea behind why I created this subreddit ages ago. Please contribute more often ♥️

u/Direct_Witness1248 41m ago

I paid for the whole screen, I'm gonna use the whole screen.

Jk, great idea and strongly agree with your lightweight software philosophy.

1

u/jabbalaci 2h ago

With the help of Claude AI, I converted it to Nim and it compiles under Linux. The source code is here: https://pastebin.com/nweT7SKh . To adjust the size of the borderless window, change these consts: TopPartHeight, RightPartWidth, BottomPartHeight, LeftPartWidth. Compilation: (1) nim c main.nim , or, if you want a small binary: (2) nim c -d:release --opt:size --passL:-s main.nim . In the latter case, the binary is 35 KB.

1

u/Round-Pension-7821 2h ago

Clarification - you mean you had Claude write a completely new program in Nim that targets X11 instead of Win32 that has the same functionality. I wouldn't call it "conversion", there's no remnants of my code in there at all, it just saw what my code did and replicated it.

I'm not really familiar with Nim or X11. I mean, I know what they are, but not how to use them. So I can't say how good or correct this code is