Mac OSX: How to detect that NO window is selected? - objective-c

I am working on the app which resizes the selected window.
It works successfully when any window is selected. But crashes when no window is selected.
Currently fetching front most window from the following code.
AXUIElementCopyAttributeValue(frontMostApp, kAXFocusedWindowAttribute, (CFTypeRef *)&frontMostWindow);
But how to detect that control is on desktop or all the windows are inactive.

AXUIElementCopyAttributeValue() returns AXError, so you can catch it and then check what happened.
AXError error = AXUIElementCopyAttributeValue(frontMostApp, kAXFocusedWindowAttribute, (CFTypeRef *)&frontMostWindow);
if (error != kAXErrorSuccess) {
//solve problems here
}
In your specific case there is a value of an error returned: kAXErrorNoValue = -25212

You can use AppleScript to do this. When creating a new project in Xcode, you can choose "Cocoa-AppleScript" as your app type by going under OS X > Other to make an app that has both Obj-C and AppleScript. You can use this code to make the app that has focus do something:
tell current app to ...
You can use this code to change the size of the window
set the bounds of the front window to {x, y, x + width, y + height}
Here, x and y are the distance from the top-left corner.
You can add this to your project and modify the size of the window that is currently at the front. This means that the frontmost window of the app with focus will be resized. This is a working and fully interactive example:
set theWindows to the windows of the current application
if the length of theWindows is 0 then
display alert "There are no windows to resize"
else
display dialog "Enter x" default answer ""
set x to text returned of result as number
display dialog "Enter y" default answer ""
set y to text returned of result as number
display dialog "Enter width" default answer ""
set width to text returned of result as number
set width to (x + width)
display dialog "Enter height" default answer ""
set height to text returned of result as number
set height to (y + height)
tell current application to set the bounds of the front window to {x, y, width, height}
end if
In Yosemite you can create apps that have nothing at their core but AppleScript with the "Script Editor" application. In Mavericks and older systems the app is called "AppleScript Editor". If you need Objective-C for other parts of your app you can create a Cocoa-AppleScript program using the method I described earlier.

Related

Java FX Dialog "appears" with no size

I'm using JFX 11 on Fedora 33 (GNU/Linux) with the Xorg GUI server (v 1.20.11), creating a dialog thus (kotlin):
fun YNdialog (txt : String) : Boolean {
val dlog = Dialog<ButtonType>()
dlog.dialogPane.apply {
contentText = txt
buttonTypes.apply {
add(ButtonType.OK)
add(ButtonType.CANCEL)
}
minWidth = 200.0
minHeight = 100.0
}
dlog.initOwner(theStage.scene.window)
val r = dlog.showAndWait()
return r.isPresent && r.get() == ButtonType.OK
}
This is called from an EventHandler<ActionEvent> associated with a Button:
if (YNdialog("hello world")) ...
There does seem to be a window created. If I remove the initOwner() call, an icon for it appears in the desktop taskbar (KDE), allowing me to do things like move it, but "maximize" and "resize" are greyed out, and the mouse cursor appears to be dragging nothing, ie., it has no width or height.
With the initOwner() it does much the same thing, except it gets no taskbar icon. Also, there is a visible vertical line one or two pixels thick where it should be (centered over the main window). What's more interesting is a second close button appears in the titlebar of the main window:
This is not part of the javafx interface, but I've never seen the window manager (?) do this before.
Occasionally (maybe one in five or ten times) the dialog does appear, and curiously,
the close button there is offset with space for a second one:
When this happens and I can dismiss the dialog window, the second close button on the main window disappears.
Using Alert
Replacing that function, etc. with:
Alert(Alert.AlertType.CONFIRMATION, "hello world").showAndWait()
.filter { res -> res == ButtonType.OK }
.ifPresent { _ -> log.msg("ok!") }
The result is identical to the YNdialog with initOwner().
Am I missing something here? I got all of this pretty much straight from the docs. I have done custom popup windows (instantiated via FXMLLoader) and have not had any problem with that. Does this experience imply the dialog hierarchy is glitchy in this context and I should roll my own?

Windows 8 24x24 badge logo image failing wac tool test

I am developing windows 8 app using tool Microsoft Visual Studio Express for Windows 8
When I am creating app packages to upload on app store it fails the WAC tool test and gives out following error.
Image reference "images\badge_24.png": The image "C:\Program Files\WindowsApps
\myproject\images\badge_24.png" has an ABGR value "0x1D5E50E9" at position (9, 0)
that is not valid. The pixel must be white (##FFFFFF) or transparent (00######).
I searched on net and found the link Badge Issue in VS update 1
I am not using 34x34 image for badge logo. I am using 24x24 image still I am getting the error by wac tool due which I can not submit this to App Store.
I tried with using 34x34 image but its not working can any one help me with this?
I know this problem very well. It is not related to the image size but to the image content. The error message is actually very precise - not all pixels in your badge logo fulfill the requirement that they are fully white ##FFFFFF or transparent 00######.
I suggest your first step is a confirmation that my answer is right. For that purpose just create a temporary 24x24 image which would be completely white. If you use this temp white logo the WAC should pass.
Next step would be to get a proper logo image. I did the following with GIMP graphic tool (http://www.gimp.org/downloads/):
Identify background color of your logo, navigate to Colors > Color to alpha and select the identified color. That makes your background transparent.
Now it's time to desaturate the whole picture by Colors > Desaturate
Restrict bits to ##FFFFFF and 00###### only: Navigate to Colors > Brightness-Contrast and set both Brightness and Contrast to the max values.
To be sure, I am right you might want to attach your current badge logo to your original question.
The solution is really simple! Just import your badge logo into Adode Photoshop and Press [Control + L] or Go to the menu [Image> Adjustments> Levels] and set the values as:
Channel: RGB
Input Levels up fields: 253; 1,00; 255
Input Levels down fields: 255; 255
Save your image!
Afterward, just redo do process of creating App Packages on visual Studio. Now Enjoy you app approved!
One way to automate the process is to write a litte C# console application that "fixes" the images:
Add a nuget reference to package Magick.NET.Core-Q8
Perform the following code to remove < 255 color channels:
foreach( string ThisFile in Directory.GetFiles( #"C:\YourUwpApplication\Assets", "LockScreenLogo.*.png" ) )
{
using( ImageMagick.MagickImage TheImage = new ImageMagick.MagickImage( ThisFile ) )
{
ImageMagick.PixelCollection Pixels = TheImage.GetPixels();
for( int IX = 0; IX < TheImage.Width; IX++ )
{
for( int IY = 0; IY < TheImage.Height; IY++ )
{
Pixels[ IX, IY ].SetChannel( 0, 255 );
Pixels[ IX, IY ].SetChannel( 1, 255 );
Pixels[ IX, IY ].SetChannel( 2, 255 );
}
}
TheImage.Write( ThisFile );
}
}
Enjoy
-Simon
Possible option (worked for me) remove:
<uap:LockScreen Notification="badgeAndTileText" BadgeLogo="" />
from Package.appxmanifest file (as xml)
If the app has nothing to do with LockScreen notifications, this seems to be an option.

Change the tile image of a shortcut tile pinned on the metro desktop

we have created a tile shortcut, which is similar to pinning the IE shortcuts on the screen. We have done this through code. We want an image should come on this tile. How do we add image to such a shortcut tile. we are running an exe first on windows 7 desktop mode and then making the pin to screen event click using the shell scripting. the tile is similar to any internet address pinned on the desktop
See this sample app...
The basic code you will need to achieve this is as follows...
Uri logo = new Uri("ms-appx:///Assets/squareTile-sdk.png");
Uri smallLogo = new Uri("ms-appx:///Assets/smallTile-sdk.png");
string tileActivationArguments = MainPage.logoSecondaryTileId + " WasPinnedAt=" + DateTime.Now.ToLocalTime().ToString();
SecondaryTile secondaryTile = new SecondaryTile(MainPage.logoSecondaryTileId,
"Title text shown on the tile",
"Name of the tile the user sees when searching for the tile",
tileActivationArguments,
TileOptions.ShowNameOnLogo,
logo);
secondaryTile.ForegroundText = ForegroundText.Dark;
secondaryTile.SmallLogo = smallLogo;
bool isPinned = await await secondaryTile.RequestCreateAsync();

How to disable logo in Windows 8 metro app live tile?

I am trying to disable the logo in my metro app live tile so that the last line of text in my tile notification will show. The Windows 8 documentation
says that there is a way to disable this logo in the Package.appxmanifest file. However, it does not specify how. I have set the ShortName in my .appxmanifest and I have also set the "Show name" field to "All Logos"; however, the default logo still appears in the bottom left-hand corner of the live tile and obscures the last line of text in my tile notification. Any ideas?
A live tile can have an image, text, or no branding. The default is the app logo, and you override this when you create a live tile update by specifying branding "none", like this:
var templateContent = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideImage);
var imageElement = (XmlElement) templateContent.GetElementsByTagName("image").Item(0);
imageElement.SetAttribute("src", string.Concat(imagePath, "wide_tile.png"));
var bindingElement = (XmlElement) templateContent.GetElementsByTagName("binding").Item(0);
bindingElement.SetAttribute("branding", "none");
var tile = new TileNotification(templateContent);
TileUpdateManager.CreateTileUpdaterForApplication().Update(tile);
You can't have both the last line of text and a short name. It's either logo/shortname or the the last line of text.
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/d7ed6580-0528-4a28-a475-731b37f2c89b

Placing a window near the system tray

I am writing a program that needs to set a window just above/below the traybar for gtk. I have tried using the 2 approaches that failed. One was using the gtk_status_icon_position_menu function and placing the window in the point where the user clicks (in the tray bar). The problem is that these solutions work in gnome(Linux) but not in Windows. In Linux they work because the window manager doesn't seem to allow placement of windows in the tray panel, honoring the closest possible. In Windows this doesn't happen and the window can go "out" of the screen which understandably is not desired.
With this said i went out for a work around. My idea was to set the window in the location of mouse click and get the x and y coordinates of a normal window placement and with it's size check if it would be within the screen boundaries. If it was not make the correction. I have came up with the functions needed but for some reason the gdk_drawable_get_size(window->window ,&WindowWidth, &WindowHeight) and other similar functions only give the correct size value after the second run of the signal function. The result of the first run is just 1 to both size and width. (I have read the issue of X11 not giving correct results, but i think this is not it)
event_button = (GdkEventButton *) event;
if (event_button->button == 1)
{
if (active == 0)
{
gboolean dummy;
gint WindowHeight, WindowWidth, WindowPosition[2];
GdkScreen *screen;
gint ScreenHeight, ScreenWidth;
dummy = FALSE;
gtk_widget_show_all(window);
gtk_window_present(GTK_WINDOW(window));
gtk_status_icon_position_menu(menu, &pos[X], &pos[Y], &dummy, statusicon);
gtk_window_move(GTK_WINDOW(window), pos[X],pos[Y]);
gdk_drawable_get_size(window->window ,&WindowWidth, &WindowHeight);
screen = gtk_status_icon_get_screen(statusicon);
ScreenWidth = gdk_screen_get_width(screen);
ScreenHeight = gdk_screen_get_height(screen);
g_print("Screen: %d, %d\nGeometry: %d, %d\n",ScreenWidth, ScreenHeight, WindowWidth, window->allocation.height);
gtk_entry_set_text(GTK_ENTRY(entry),"");
active = 1;
return TRUE;
}
How can i do what i want in a portable way?
I think gtk_status_icon_position_menu should work fine, as i used it for the same purpose.
Are you trying this stuff with X11, What is the actual result you are getting.