How to config awesome so it would start new application with two windows aligned like this:
----------------
|xxxxxxxxxx####|
|xxxxxxxxxx####|
|xxxxxxxxxx####|
|xxxxxxxxxx####|
----------------
where "x" is for example conversation window in pidgin and '#' is buddy list window.
In general I would like to specify width of right window and put it on the right side (maximized vertically) and the other window should take the remaining space.
I already have some almost-working code, but it behaves strangely (it setups everything correct for pidgin, but it doesn't for gimp and v_sim, and occasionally without any known to me reason it changes geometry of the left window. Or when I start application (v_sim) it isn't placed in correct positions and it isn't maximized vertically, but when I then restart awesome, it places it correctly. So I guess that this application changes something when it starts.
Here is code which I use now:
awful.rules.rules = {
...
{ rule = { class = "Pidgin", role = "buddy_list" },
properties = {
floating = true
},
callback = function( c )
local w_area = screen[ c.screen ].workarea
local winwidth = 340
c:struts( { right = winwidth } )
c:geometry( { x = w_area.width - winwidth, width = winwidth, y = w_area.y, height = w_area.height } )
end
},
{ rule = { class = "Pidgin", role = "conversation" },
properties = {
floating = true,
x = 0,
maximized_vertical = true,
maximized_horizontal = true
},
callback = awful.client.setslave
},
...
}
I had this exact same problem, but I wanted a large Firefox window on the left with a small terminal on the right. To get it to work I dedicated a tag for this purpose with a tile-left layout and adjusted the width factor (i.e. the operation normally performed by CTRL-L).
Add the following to the end of rc.lua where yourtag is the tag in which you would like to place these windows. The 0.15 value can be adjusted to your taste.
awful.tag.viewonly(yourtag)
awful.tag.incmwfact(0.15, yourtage)
Also, using the awful.client.setslave for the window that you want on the right ensures that they don't get switched.
{
rule = { class = "URxvt" },
callback = awful.client.setslave
},
You may also direct certain applications to a tag using the tag property.
{
rule = { class = "Firefox" },
properties = { tag = browse }
},
{
rule = { class = "URxvt", instance = "browse" },
properties = { tag = browse },
},
I then created a binding to open these applications as follows.
-- Custom programs
awful.key({ modkey, "Shift" }, "b", function()
awful.tag.viewonly(browse)
awful.util.spawn_with_shell("urxvt -name browse -e newsbeuter")
awful.util.spawn("firefox")
end)
This is the final result:
Alternatively, you can use a floating contact list window with struts.
This prevents the contact list window from being maximized when no message-window is present.
Also, it allows the CL-window to be placed next to arbitrary (tiling) windows.
Check out: http://www.bramschoenmakers.nl/en/node/738
Although his implementation is a bit buggy for my version of awesome.
The problem is that it does not adjust for struts that have already been set.
My implementation:
{ rule = { class = "Pidgin", role = "buddy_list" },
properties = {floating=true,
maximized_vertical=true, maximized_horizontal=false },
callback = function (c)
local cl_width = 250 -- width of buddy list window
local scr_area = screen[c.screen].workarea
local cl_strut = c:struts()
-- scr_area is affected by this client's struts, so we have to adjust for that
if c:isvisible() and cl_strut ~= nil and cl_strut.left > 0 then
c:geometry({x=scr_area.x-cl_strut.left, y=scr_area.y, width=cl_strut.left})
-- scr_area is unaffected, so we can use the naive coordinates
else
c:struts({left=cl_width, right=0})
c:geometry({x=scr_area.x, y=scr_area.y, width=cl_width})
end
end },
This puts the CL window on the left and allocating a fixed space for it.
(You don't need any rule for the conversation-window)
Related
How to make the Awesome's window(client) moving behavior the similar like DWM's ViewonTag patch
Follow a window to the tag it is being moved to.
Patch 20210312 prevents the window being followed if it is being moved
to the "all" tag.
What code should I write here?
awful.key({ modkey, "Shift" }, "#" .. i + 9,
function ()
if client.focus then
local tag = client.focus.screen.tags[i]
if tag then
client.focus:move_to_tag(tag)
--- ???????? ---
--- How to follow the client window? ---
end
end
end,
{description = "move focused client to tag #"..i, group = "tag"}),
After many tries I solved this. But I don't know why it needs to declare the variables screen and tag2. Why can't use tag:view_only()
-- Move client to tag.
awful.key({ modkey, "Shift" }, "#" .. i + 9,
function ()
if client.focus then
local tag = client.focus.screen.tags[i]
if tag then
client.focus:move_to_tag(tag)
local screen = awful.screen.focused()
local tag2 = screen.tags[i]
tag2:view_only()
end
end
end,
{ description = "move focused client to tag #"..i, group = "tag" }
),
Using PencilKit for iOS, how do I set the eraser tool to .bitmap for PKToolPicker?
I can't find any setting for PKToolPicker. Trying to use PKCanvasView to observe and set the tool's eraserType as .bitmap also does not work.
override func toolPickerSelectedToolDidChange(_ toolPicker: PKToolPicker) {
var tool = toolPicker.selectedTool as? PKEraserTool
if tool != nil {
tool?.eraserType = .bitmap
}
}
The PKEraser is a struct, so when you change its eraserType, you're actually modifying a copy of the tool that's being used in the canvas.
What you need to do is simply set the PKCanvasView tool property and it will work.
override func toolPickerSelectedToolDidChange(_ toolPicker: PKToolPicker) {
var tool = toolPicker.selectedTool as? PKEraserTool
if tool != nil {
tool?.eraserType = .bitmap
}
// this line below will do the trick
canvasView.tool = tool
}
Let me know if it worked! 😊
Applies to iOS 13 and iOS 14
To set the toolpicker's selected tool as a bitmap eraser (where toolPicker is the PKToolPicker):
toolPicker?.selectedTool = PKEraserTool(.bitmap)
To set the canvas view's tool to a bitmap eraser (where canvasView is the PKCanvasView):
canvasView.tool = PKEraserTool(.bitmap)
This code, based on your example, will keep the toolpicker's erase tool as bitmap(pixel eraser) even if vector(object eraser) was chosen. (tested on iOS 14)
func toolPickerSelectedToolDidChange(_ toolPicker: PKToolPicker) {
if toolPicker.selectedTool is PKEraserTool {
toolPicker.selectedTool = PKEraserTool(.bitmap)
}
}
How would one go about adding programmatically triggered touch/mouse events in Matter.js? I have a few collision events set up for the engine, but can not trigger a mouseup event that stops the current dragging action. I've tried various combinations of targeting the canvas element, the mouse/mouseConstraint, and the non-static body.
If you, like me, came here trying to figure out how to be able to click on a Matter.js body object, let me give you one way. My goal in my project was to assign some attributes to my rectangle objects and call a function when they were clicked on.
The first thing to do was to distinguish between dragging and clicking, so I wrote(using Jquery):
$("body").on("mousedown", function(e){
mouseX1 = e.pageX;
mouseY1 = e.pageY;
});
$("body").on("mouseup", function(e){
mouseX2 = e.pageX;
mouseY2 = e.pageY;
if((mouseX1 == mouseX2) && (mouseY1 == mouseY2)){
//alert("click!\n" + mouseX2 + " " + mouseY2 +"\n");
var bodiesUnder = Matter.Query.point(books, { x: mouseX2, y: mouseY2 });
//alert("click!\n" + mouseX2 + " " + mouseY2 +"\n");
if (bodiesUnder.length > 0) {
var bodyToClick = bodiesUnder[0];
alert(bodyToClick.title2);
}
}
});
This was accomplished when listening for "mouseup" and asking if ((mouseX1 == mouseX2) && (mouseY1 == mouseY2)).
Second- the juicy part- create a var array to hold the objects, or 'bodies', we are going to dig up under the mouse. Thankfully there's this function:
var bodiesUnder = Matter.Query.point(books, { x: mouseX2, y: mouseY2 });
For the first element in here I entered "books". For you this needs to be the name of an array you've put all your objects, or 'bodies' into. If you don't have them in an array, it's not hard to throw them all in, like so:
var books = [book1, book2, book3];
Once that was all done, I was able to alert(book1.title2) to see what the title of that book (body) is. My bodies were coded as follows:
var book2 = Bodies.rectangle(390, 200, 66, 70, {
render : {
sprite : {
texture: "img/tradingIcon.jpg"
}
},
restitution : 0.3,
title1 : 'Vanessa and Terry',
title2 : 'Trading'
});
Hope that helps! This one had me hung up for a whole day.
It turns out I had incorrectly configured the Matter.Mouse module, and was re-assigning the mouse input that had already been set in MouseConstraint. The following works in regards to my original question:
Matter.mouseConstraint.mouse.mouseup(event);
Is it possible to create a single gravity / force point in matter.js that is at the center of x/y coordinates?
I have managed to do it with d3.js but wanted to enquire about matter.js as it has the ability to use multiple polyshapes.
http://bl.ocks.org/mbostock/1021841
The illustrious answer has arisen:
not sure if there is any interest in this. I'm a fan of what you have created. In my latest project, I used matter-js but I needed elements to gravitate to a specific point, rather than into a general direction. That was very easily accomplished. I was wondering if you are interested in that feature as well, it would not break anything.
All one has to do is setting engine.world.gravity.isPoint = true and then the gravity vector is used as point, rather than a direction. One might set:
engine.world.gravity.x = 355;
engine.world.gravity.y = 125;
engine.world.gravity.isPoint = true;
and all objects will gravitate to that point.
If this is not within the scope of this engine, I understand. Either way, thanks for the great work.
You can do this with the matter-attractors plugin. Here's their basic example:
Matter.use(
'matter-attractors' // PLUGIN_NAME
);
var Engine = Matter.Engine,
Events = Matter.Events,
Runner = Matter.Runner,
Render = Matter.Render,
World = Matter.World,
Body = Matter.Body,
Mouse = Matter.Mouse,
Common = Matter.Common,
Bodies = Matter.Bodies;
// create engine
var engine = Engine.create();
// create renderer
var render = Render.create({
element: document.body,
engine: engine,
options: {
width: Math.min(document.documentElement.clientWidth, 1024),
height: Math.min(document.documentElement.clientHeight, 1024),
wireframes: false
}
});
// create runner
var runner = Runner.create();
Runner.run(runner, engine);
Render.run(render);
// create demo scene
var world = engine.world;
world.gravity.scale = 0;
// create a body with an attractor
var attractiveBody = Bodies.circle(
render.options.width / 2,
render.options.height / 2,
50,
{
isStatic: true,
// example of an attractor function that
// returns a force vector that applies to bodyB
plugin: {
attractors: [
function(bodyA, bodyB) {
return {
x: (bodyA.position.x - bodyB.position.x) * 1e-6,
y: (bodyA.position.y - bodyB.position.y) * 1e-6,
};
}
]
}
});
World.add(world, attractiveBody);
// add some bodies that to be attracted
for (var i = 0; i < 150; i += 1) {
var body = Bodies.polygon(
Common.random(0, render.options.width),
Common.random(0, render.options.height),
Common.random(1, 5),
Common.random() > 0.9 ? Common.random(15, 25) : Common.random(5, 10)
);
World.add(world, body);
}
// add mouse control
var mouse = Mouse.create(render.canvas);
Events.on(engine, 'afterUpdate', function() {
if (!mouse.position.x) {
return;
}
// smoothly move the attractor body towards the mouse
Body.translate(attractiveBody, {
x: (mouse.position.x - attractiveBody.position.x) * 0.25,
y: (mouse.position.y - attractiveBody.position.y) * 0.25
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/matter-js/0.12.0/matter.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/matter-attractors#0.1.6/build/matter-attractors.min.js"></script>
Historical note: the "gravity point" functionality was proposed as a feature in MJS as PR #132 but it was closed, with the author of MJS (liabru) offering the matter-attractors plugin as an alternate. At the time of writing, this answer misleadingly seems to indicate that functionality from the PR was in fact merged.
Unfortunately, the attractors library is 6 years outdated at the time of writing and raises a warning when using a newer version of MJS than 0.12.0. From discussion in issue #11, it sounds like it's OK to ignore the warning and use this plugin with, for example, 0.18.0. Here's the warning:
matter-js: Plugin.use: matter-attractors#0.1.4 is for matter-js#^0.12.0 but installed on matter-js#0.18.0.
Behavior seemed fine on cursory glance, but I'll keep 0.12.0 in the above example to silence it anyway. If you do update to a recent version, note that Matter.World is deprecated and should be replaced with Matter.Composite and engine.gravity.
last night a have an autolayout issue. I was googling and try to find something similar in SO. Even the apple doc doesn't point me to the right direction. Maybe my search terms are completely wrong.
Maybe you guys can bring some light into my darkness.
I added a NSOutlineView in storyboard and added some constraints to the NSTableCellView. As you can see, i added a trailing space to Superview of 50:
My example code adds some foo's and bar's into the outlineView by identifyer:
func outlineView(outlineView: NSOutlineView, viewForTableColumn tableColumn: NSTableColumn?, item: AnyObject) -> NSView? {
if tableColumn?.identifier == "NAME_COLUMN" {
cell = outlineView.makeViewWithIdentifier("NAME_COLUMN", owner: self) as NSTableCellView
cell.textField!.stringValue = "foo"
cell.textField!.editable = true
cell.textField!.delegate = self
} else
if tableColumn?.identifier == "VALUE_COLUMN" {
cell = outlineView.makeViewWithIdentifier("VALUE_COLUMN", owner: self) as NSTableCellView
cell.textField!.stringValue = "bar"
cell.textField!.editable = true
cell.textField!.delegate = self
}
return cell
}
But the trailing space will not show up in my running application!
I even try to set the cell display:
cell.needsDisplay = true
cell.needsLayout = true
cell.needsUpdateConstraints = true
or - according to someone on the internet - add "requiresConstraintBasedLayout":
class func requiresConstraintBasedLayout() -> Bool {
return true
}
but all without luck. The trailing space do not appears and the bar's on the right side border looks awful.
How do i use a TableViewCell inside a OutlineView with a trailing space?
Thanks a lot for any kind of hint.
ps